Connect your iOS/OSX applications written in Objective-C or Swift to server applications that communicate with the DDP protocol created by Meteor and, if required by your server, authenticate with it.
Note:
supports meteor 0.8.2 and above.
If you need to migrate please see the srp-upgrade-support branch
This is unsupported so don't come crying if it eats your cat! or destroys any data.
(void)logonWithOAuthAccessToken: (NSString *)accessToken serviceName: (NSString *) serviceName responseCallback: (MeteorClientMethodCallback)responseCallback;
Please require the following project to your meteor server for this to work.
https://github.com/jasper-lu/facebook-ddp
Hopefully meteor will support this natively in the future meteor/meteor#3515
ObjectiveDDP should run well with iOS projects using ARC and iOS 7.1 or above. Check out the example application and the project wiki for more information. Here is a sneak peak:
pod 'ObjectiveDDP', '~> 0.2.0'
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 protocol 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];