我想将字典从 iPhone 发送到 watchOS 2 中的 Watchkit。
在 watchOS 1 中,它适用于我的应用程序组,但在 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.
关于swift - 如何在 SWIFT 的 OS2 中将数据从 Iphone 发送到 Watchkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30907784/