获得nil或错误代码的不一致结果:在应用程序func handleWatchKitExtRequest中调用Parse代码时,没有与查询匹配的结果。 (使用Apple iOS SDK 8.4和Parse 1.7.5。)。有人能给我一些关于如何处理这个问题的见解吗?
相同的Parse代码在iPhone ViewController中调用时或在func didFinishLaunchingWithOptions下的AppDelegate中获取正确的Parse数据结果(获得正确的数据结果)。当我将相同的代码放入此函数并且它停止工作时,无法弄清楚为什么会发生这种情况???
以下是我正在使用的代码:
来自Watch Extension Interface Controller的调用:
var message = ["content":"runParseCode"]
WKInterfaceController.openParentApplication(message, reply: {(reply, error) -> Void in
println(reply)
})
从iPhone AppDelegate func handleWatchKitExtRequest中调用:
func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) {
if let message = userInfo as? [String:String] {
if let content = message["content"] {
if content == "runParseCode" {
var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("2ConDf1oj8") {
(gameScore:PFObject?, error:NSError?)->Void in
if error == nil {
//reply(["content":"\(gameScore)"])
if let score = gameScore!["score"] as? Int {
reply(["content":score])
}
} else {
let errorString = error!.userInfo!["error"] as? NSString as! String
reply(["content":"\(errorString)"])
}
}
} else {
reply(["content":"Not proper authorization!"])
}
}
}
}
答案 0 :(得分:0)
您使用的是什么版本的Xcode?我发现6.4给了我很多函数调用的问题。我回到了Xcode 6.3,一切正常!