如何快速将数据从iphone发送到watchkit [英] How to send data from iphone to watchkit in swift
本文介绍了如何快速将数据从iphone发送到watchkit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个示例项目,我喜欢将数据从 iphone 发送到 WatchKit.我不知道如何做到这一点.任何帮助将不胜感激.提前致谢
I am doing a sample project in which i like to send data from iphone to WatchKit. I have no idea of how to do this. Any help will be appreciated. Thanks in advance
推荐答案
在 AppDelegate 中添加这个方法:
Add this method in the AppDelegate:
func application(application: UIApplication!,
handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!,
reply: (([NSObject : AnyObject]!) -> Void)!)
{
//define your dictionary
reply(yourDict)
}
在 Apple Watch 扩展中的任意位置添加:
Add this anywhere in the 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
参数中的字典.
The first function will trigger with WKInterfaceController.openParentApplication
and will reply the dictionary in the reply
parameter.
开发者论坛:https://devforums.apple.com/message/1082689#1082689
这篇关于如何快速将数据从iphone发送到watchkit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文