我想在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.