问题描述
我想将iPhone的字典发送到watchOS 2中的Watchkit.
I want to send a dictionary from iPhone to Watchkit in watchOS 2.
在watchOS 1中,它对我来说适合应用组,但在watchOS 2中,我知道我们必须使用WCSession
,但我不知道如何使用它.
In watchOS 1 it works fine for me with appgroups but in watchOS 2 I know that we have to use WCSession
but I don't know how to use it.
请帮助我找到解决方法.
Please help me find the solution.
推荐答案
此博客文章应该可以帮助您.
在那篇文章中:首先,您将像这样创建并激活WCSession:
From that post: First, you'll create and activate a WCSession like so:
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:
(开发者文档).请注意,根据Apple的" watchOS2过渡指南,"
Then, on the receiving end, you'll need to implement session:didReceiveUserInfo:
(Developer documentation). Note, according to Apple's "watchOS2 Transition Guide,"
这篇关于如何在SWIFT的OS2中将数据从Iphone发送到Watchkit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!