Giter VIP home page Giter VIP logo

objectiveddp's Introduction

ObjectiveDDP

Build Status

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.

What's Inside

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:

Integrate it with your project using CocoaPods:
pod 'ObjectiveDDP', '~> 0.1.3'

For more information about this, check out Linking and Building in the wiki.

Load the library and connect to a meteor server:
- (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];
}
Logon using bcrypt authentication:
[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];
}];
Call a remote function on the server:
[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];
}];
Listen for updates that meteor sends regarding the collection previously subscribed to:
- (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];
}
Send CRUD updates to the meteor server to change the collection:
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];

License

MIT

objectiveddp's People

Contributors

boundsj avatar charlesvallieres avatar ewindso avatar martinc avatar mikey0000 avatar nevyn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.