swift - 如何快速将数据从iphone发送到watchkit

标签 swift watchkit

我正在做一个示例项目,我想在其中将数据从 iphone 发送到 WatchKit。我不知道该怎么做。任何帮助将不胜感激。提前致谢

最佳答案

在 AppDelegate 中添加此方法:

func application(application: UIApplication!,
handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!,
   reply: (([NSObject : AnyObject]!) -> Void)!)
{
   //define your dictionary
   reply(yourDict)
}

将此添加到 Apple Watch Extension 的任何位置:

var dict = ["test" : 4] //your dictionary/request to sent to the iPhone
if !WKInterfaceController.openParentApplication(dict, reply: { (reply,error) -> Void in
    println("\(reply)") //your reply data as Dictionary
}) {
    println("ERROR")
}

第一个函数将通过 WKInterfaceController.openParentApplication 触发,并将在 reply 参数中回复字典。

开发者论坛: https://devforums.apple.com/message/1082689#1082689

关于swift - 如何快速将数据从iphone发送到watchkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28762906/

相关文章:

ios - Swift 对多关系 .removeFromMethod() 不更新 NSFetchedResultsController

ios - 如何在 Swift 中从 UIImage 转换为 HEIF/HEIC 数据?

ios - 我无法在 uitableviewcell 中创建 socket

ios - 如何在 WatchKit 中使用等宽字体

swift - WatchKit 2 复杂文本仅在预览中显示

iOS WKWebview 如何检测何时单击 <a> 标签内的图像

ios - View Controller 的 Swift 方向覆盖

ios - Swift 中的算术运算符数组

swift - 错误 : "cannot invoke initializer" for function to be executed on Watch OS only

ios - WCSession - PayloadTooLarge