【问题标题】:How to send data from iphone to watchkit in swift如何快速将数据从 iphone 发送到 watchkit
【发布时间】:2015-02-27 10:31:25
【问题描述】:

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

【问题讨论】:

    标签: swift watchkit


    【解决方案1】:

    在 AppDelegate 中添加这个方法:

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

    将此添加到 Apple Watch 扩展中的任何位置:

    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

    【讨论】:

    • 我想做的是从服务器获取数据,将其存储在手机端的 coredata 中,然后从 coredata 中获取并发送 watchkit。我可以用上面的代码完成吗?
    • AFAIK,这是为了将数据从 Watch 发送到 iPhone,而不是从 iPhone 发送到 Watch
    • 这会双向发送数据,只需将您的数据放入回复字典中
    猜你喜欢
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多