WatchOS 2应用程序组不将NSUserDefaults共享给Watch Extension

时间:2016-01-18 20:13:20

标签: ios xcode swift swift2 nsuserdefaults

据我所知,在watchOS 2中,您无法写入共享的应用群组,但根据Apple's documentation 可以>向他们进行阅读:

  

在watchOS 2中,您的WatchKit扩展程序只能从中读取值   数据库中。

我将studentUsernamestudentPassword写入标识为group.com.spcc.BlahBlah的群组。 WatchKit Extension和主iOS应用都启用了应用程序组功能。

我可以使用我的iOS应用中的以下代码从group.com.spcc.BlahBlah读取我的两个值,但不能在awakeWithContext(context: AnyObject?)函数的Watch App Extension中读取我的接口控制器:

let studentUsername = NSUserDefaults(suiteName: "group.com.spcc.BlahBlah")?.objectForKey("studentUsername")! as! String
let studentPassword = NSUserDefaults(suiteName: "group.com.spcc.BlahBlah")?.objectForKey("studentPassword")! as! String

在Watch App Extension中使用该代码将我的值返回为nil。可能是什么原因?

0 个答案:

没有答案
相关问题