Note:
Recent changes to meteor (https://github.com/meteor/meteor/blob/release/0.8.2/History.md)
have fundamentally changed the way authorization works. Because of this, the current
version of the master branch of this project (and all future releases) will only be
compatible with meteor 0.8.2 and above. Please update your meteor server
as soon as possible.
Connect your iOS applications written in Objective-C to server applications that communicate with the DDP protocol created by Meteor and, if required by your server, authenticate with it.
ObjectiveDDP should run well with iOS projects using ARC and iOS 7.0 or above. Check out the example application and the project wiki for more information. Here is a sneak peak:
pod 'ObjectiveDDP', '~> 0.1.6'
For more information about this, check out Linking and Building in the wiki.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.meteorClient = [[MeteorClient alloc] init];
[self.meteorClient addSubscription:@"awesome_server_mongo_collection"];
ObjectiveDDP *ddp = [[ObjectiveDDP alloc] initWithURLString:@"wss://awesomeapp.meteor.com/websocket" delegate:self.meteorClient];
self.meteorClient.ddp = ddp;
[self.meteorClient.ddp connectWebSocket];
}
[self.meteor signupWithUsername:self.username.text password:self.password.text fullname:self.fullname responseCallback:^(NSDictionary *response, NSError *error) {
if (error) {
[self handleFailedAuth:error];
return;
}
[self handleSuccessfulAuth];
}];
or with email
[self.meteor signupWithEmail:self.email.text password:self.password.text fullname:self.fullname.text responseCallback:^(NSDictionary *response, NSError *error) {
if (error) {
[self handleFailedAuth:error];
return;
}
[self handleSuccessfulAuth];
}];
or with both
[self.meteor signupWithUsernameAndEmail:self.username.text email:self.email.text password:self.password.text fullname:self.fullname.text responseCallback:^(NSDictionary *response, NSError *error) {
if (error) {
[self handleFailedAuth:error];
return;
}
[self handleSuccessfulAuth];
}];
[self.meteor logonWithUsername:self.username.text password:self.password.text responseCallback:^(NSDictionary *response, NSError *error) {
if (error) {
[self handleFailedAuth:error];
return;
}
[self handleSuccessfulAuth];
}];
or with email
[self.meteor logonWithEmail:self.email.text password:self.password.text responseCallback:^(NSDictionary *response, NSError *error) {
if (error) {
[self handleFailedAuth:error];
return;
}
[self handleSuccessfulAuth];
}];
or if you accept both
[self.meteor logonWithUsernameOrEmail:self.usernameOrEmail.text password:self.password.text responseCallback:^(NSDictionary *response, NSError *error) {
if (error) {
[self handleFailedAuth:error];
return;
}
[self handleSuccessfulAuth];
}];
[self.meteor callMethodName:@"sayHelloTo" parameters:@[self.username.text] responseCallback:^(NSDictionary *response, NSError *error) {
NSString *message = response[@"result"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Meteor Todos"
message:message
delegate:nil
cancelButtonTitle:@"Great"
otherButtonTitles:nil];
[alert show];
}];
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveAddedUpdate:)
name:@"awesome_server_mongo_collection_added"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveRemovedUpdate:)
name:@"awesome_server_mongo_collection_removed"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveChangeUpdate:)
name:@"awesome_server_mongo_collection_changed"
object:nil];
}
NSString *message = @"I am the walrus";
NSString *anId = [[NSUUID UUID] UUIDString];
NSArray *parameters = @[@{@"_id": anId,
@"msg": message,
@"owner": self.userId,
@"info": self.importantInformation}];
// add a document
[self.meteor callMethodName:@"/awesome_server_mongo_collection/insert"
parameters:parameters
responseCallback:nil];
// then remove it
[self.meteor callMethodName:@"/awesome_server_mongo_collection/remove"
parameters:@[@{@"_id": anId}]
responseCallback:nil];
MeteorClientConnectionReadyNotification - When the server responds as accepting the DDP protocal version to communicate on, you won't be able to call any methods to meteor until this happens
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reportConnection) name:MeteorClientDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reportConnectionReady) name:MeteorClientConnectionReadyNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reportDisconnection) name:MeteorClientDidDisconnectNotification object:nil];