0

I am trying out the objectiveDDP library to connect my iOS app to my Meteor app. I am running my meteor app on localhost:3000 and I am getting this error when I try to login:

Error Domain=boundsj.objectiveddp.transport Code=0 "You are not connected" UserInfo=0x7fe33b440500 {NSLocalizedDescription=You are not connected}

*Note - I have not done anything to the server to support this, I assuming that it is supported out of the box.

I'm not sure if the url I put in is correct because I couldn't find the documentation for which url I should connect to when using ObjectiveDDP.

Here is my code:

var meteorClient: MeteorClient = MeteorClient(DDPVersion: "1")

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    self.meteorClient.addSubscription("someSubscription")

    var ddp = ObjectiveDDP(URLString: "ws://localhost:3000/websocket", delegate: self.meteorClient)
    self.meteorClient.ddp = ddp;
    self.meteorClient.ddp.connectWebSocket()

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "reportConnection", name: MeteorClientDidConnectNotification, object: nil)
}

func reportConnection() {

    println("================> connected to server!")

    println(self.meteorClient.connected)
    self.meteorClient.logonWithEmail("blob@schmoe.com", password: "password", responseCallback: {
        (response, error) -> Void in
        if (error != nil) {
            println("*****Error******")
            println(error);
            return;
        }

        println(response);

    })
}

*Update So I try to check whether my meteorClient is connected to the server before I login. I added

NSNotificationCenter.defaultCenter().addObserver(self, selector: "reportConnection", name: MeteorClientDidConnectNotification, object: nil)

To get notify when I am connected. However, when the DidConnectNotification is receive, I check self.meteorClient.connected and got false.

harinsa
  • 3,176
  • 5
  • 33
  • 53

3 Answers3

0

Change your DDPVersion from 1 to pre2

var meteorClient: MeteorClient = MeteorClient(DDPVersion: "pre2")
Matt Privman
  • 6,406
  • 2
  • 20
  • 26
0

maintainer of said library, can you specify what versions of ObectiveDDP and meteor you are using? First try using ObectiveDDP from master not cocoapods. Your url is correct. First thing to check also, do the sample apps connect to your server?

Can you try your login by using a button instead, I think your hitting a race condition. This is something that could use a bit of tidy up.

Mikey0000
  • 96
  • 3
  • I'm using Meteor 1.0.4.2 and just changed ObjectiveDDP to master version (0.1.9). Also have change DDP version to "pre2" (not sure why). Still doesn't work. The sample apps works though. – harinsa Mar 23 '15 at 02:25
  • I am getting `DidConnectNotification`, but I am cannot logon. (I can on the sample app) – harinsa Mar 23 '15 at 02:28
  • 1
    Can you try your login by using a button instead, I think your hitting a race condition. This is something that could use a bit of tidy up. – Mikey0000 Mar 23 '15 at 22:14
  • logging in with a button works!, can you edit you answer so I can mark it as correct? – harinsa Mar 25 '15 at 02:39
0

I realize this is old, but thought I could help someone in the future. The issue seems to be that you used MeteorClientDidConnectNotification to decide when to start the login procedure. You should wait for the subsequent notification - MeteorClientConnectionReadyNotification. The button "fixed" it because you coincidentally waited after the MeteorClientDidConnectNotification for the client to become ready and for you to start the login procedure.

Peter
  • 1,031
  • 9
  • 12