Meteor login from iOS (Meteor-iOS)


#1

We have a meteor server and an iOS app created in Swift. We are using the Meteor-iOS framework and we need to log in a user via the server. Is it possible to call a method like Meteor.callMethodWithName(“customLoginMethod, parameters: [credentialtoken]”) from iOS ?
We found this method:
METAccount.init(userID: String, resumeToken: <#T##String#>, expiryDate: <#T##NSDate?#>)
Can we use this to login?

Any help is much appreciated - thank you.


#2

Don’t know the answer, but am very interested in your experience with Swift + Meteor-iOS.


#3

Well, there are three main issues

  1. There is very little documentation to speak of
    https://cocoapods.org/pods/Meteor
  2. MDG is not prioritising iOS support
  3. You will receive collections in this strange cursor that wraps a Dictionary/Array

Other than that it is awesome.

The most stable meteor framework in our experience is Meteor-iOS, it is made by Martijn Walraven who now works for the MDG.
I am hoping he will be able to help me out on this question… :wink:


#4

It depends on what you want to do exactly, but you should be able to call Meteor.loginWithMethod, which will log you in automatically based on the method result. See this issue for some examples.


#5

When I try that Method in swift I get error: Value of type ‘METDDPClient’ has no member 'loginWithMethod’
Did you mean to do this on the server or from iOS ?


#6

Check out the docs. You need to call

Meteor.loginWithMeteorDeveloperAccount
Meteor.loginWithFacebook
Meteor.loginWithGithub
Meteor.loginWithGoogle
Meteor.loginWithMeetup
Meteor.loginWithTwitter
Meteor.loginWithWeibo

#7

We don’t use any of these services, but thank you.
This solved it for us:

   Meteor.callMethodWithName("login", parameters: [["certificate" : true, "token" : token]]) { (response, error) -> Void in
        if error != nil {
            self.handleUnsuccessfulLoginToMeteor(error)
            return
        } else{
            self.parseLoginCredentials(response!)
        }
    }
}

    
func parseLoginCredentials(response:AnyObject){
    let userId = response["id"] as! String
    let resumeToken = response["token"] as! String
    let expiryDate = response["tokenExpires"] as! NSDate

    METAccount.setDefaultAccount(METAccount.init(userID: userId, resumeToken: resumeToken, expiryDate: expiryDate))
    METAccount.initialize()
}

I am a bit unsure about this part though:

METAccount.setDefaultAccount(METAccount.init(userID: userId, resumeToken: resumeToken, expiryDate: expiryDate))
METAccount.initialize()