加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在SWIFT中将数据从Iphone发送到OS2中的Watchkit

发布时间:2020-12-14 05:38:46 所属栏目:百科 来源:网络整理
导读:我想在watchOS 2中从iPhone发送一个字典到Watchkit. 在watchOS 1中,它适用于appgroups,但在watchOS 2中,我知道我们必须使用WCSession,但我不知道如何使用它. 请帮我找到解决方案. 这个 blog post应该可以帮到你. 从那篇文章:首先,您将创建并激活WCSession,
我想在watchOS 2中从iPhone发送一个字典到Watchkit.

在watchOS 1中,它适用于appgroups,但在watchOS 2中,我知道我们必须使用WCSession,但我不知道如何使用它.

请帮我找到解决方案.

这个 blog post应该可以帮到你.

从那篇文章:首先,您将创建并激活WCSession,如下所示:

if (WCSession.isSupported()) {
    let session = WCSession.defaultSession()
    session.delegate = self
    session.activateSession()
}

转移字典:

let applicationDict = // Create a dict of application data
let transfer = WCSession.defaultSession().transferUserInfo(applicationDict)

然后,在接收端,您将需要实现session:didReceiveUserInfo:(Developer documentation).请注意,根据Apple的“watchOS2 Transition Guide”

To begin communication,both your Watch app and your iOS app must have an active WCSession object. Typically,each app creates,configures,and activates a session object at launch time and stores a reference to it in a central location. When you want to send data,you retrieve the session object and call its methods.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读