WatchKit:与手机应用程序通信时出错

时间:2015-07-16 20:40:40

标签: ios swift watchkit

我正在尝试与iPhone应用程序进行通信。在Watch Controller上我有以下代码:

 func requestDataFromPhone(messageText: String) {
        var infoDictionary = Dictionary<String,String>()
        infoDictionary["GetAppointmentString"] = "message"
        WKInterfaceController.openParentApplication(infoDictionary) {
            (replyDictionary, error) -> Void in
            println("we made it!")
            if let castedResponseDictionary = replyDictionary as? [String: String],
                responseMessage = castedResponseDictionary["message"]
            {
                println(responseMessage)
                self.appointmentString.setText(responseMessage)
            }
        }
    }

在iPhone应用程序的AppDelegate上,我有以下代码:

 func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) {

        let response = "Appointment at noon tomorrow"
        let responseDictionary = ["message" : response]
        if let infoDictionary = userInfo as? [String: String],
            message = infoDictionary["GetAppointmentString"]
        {
             reply(responseDictionary)
        }
        reply(responseDictionary)
    }

我总是收到以下错误:

  

“Error Domain = com.apple.watchkit.errors Code = 2 \”The   iPhone应用程序中的UIApplicationDelegate从未调用过reply()    - [UIApplicationDelegate应用程序:handleWatchKitExtensionRequest:reply:] \“   UserInfo = 0x60800006b580 {NSLocalizedDescription = The   iPhone应用程序中的UIApplicationDelegate从未调用过reply()    - [UIApplicationDelegate应用程序:handleWatchKitExtensionRequest:reply:]}“

我在这里缺少什么?任何指针都会有所帮助。 感谢。

0 个答案:

没有答案