我正在尝试使用ObjectiveDDP库将我的 iOS 应用程序连接到我的 Meteor 应用程序。我正在运行我的流星应用程序,localhost:3000
当我尝试登录时出现此错误:
Error Domain=boundsj.objectiveddp.transport Code=0 "You are not connected" UserInfo=0x7fe33b440500 {NSLocalizedDescription=You are not connected}
*注意- 我没有对服务器做任何事情来支持这一点,我假设它是开箱即用的。
我不确定我输入的 url 是否正确,因为我找不到在使用 ObjectiveDDP 时应该连接到哪个 url 的文档。
这是我的代码:
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);
})
}
*更新
所以我尝试meteorClient
在登录之前检查我是否已连接到服务器。我添加了
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reportConnection", name: MeteorClientDidConnectNotification, object: nil)
当我连接时得到通知。但是,当收到 DidConnectNotification 时,我检查self.meteorClient.connected
并得到false。