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 SRP. Out of the box, this library allows your iOS applications to communicate and authenticate with Meteor servers or any server using the DDP/SRP protocols.
ObjectiveDDP should run well with iOS projects using ARC and iOS 6.0 or above. Check out the example application and the project wiki for more information. Here is a sneak peak:
- (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 logonWithUsername:self.username.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/insert/remove"
parameters:@[@{@"_id": anId}]
responseCallback:nil];