![](/img/trans.png)
[英]Swift3: Empty fetch when accessing Core Data from Watch Extension via AppGroups
[英]Passing Data from Watch to iPhone using Appgroups
我正在一個項目中,該數據使用Appgroup將數據從Apple Watch App傳遞到iPhone App。 我的代碼無法正常工作,我不確定為什么。 希望有人可以幫助我! :)
發送數據Apple Watch
@IBAction func senddata() {
let group = "group.pairedapp"
let shared = UserDefaults(suiteName: group)
let ok = "works"
shared!.setValue(ok, forKey: "status")
shared!.synchronize()
}
在iPhone上獲取數據
@IBAction func getWatchData(_ sender: Any) {
let group = "group.pairedapp"
let shared = UserDefaults(suiteName: group)
let get = shared!.value(forKey: "status")
if get != nil {
print("works")
}
else{
print("OO NO!")
}
}
由於watchOS2
的引入, watchOS
應用程序不再僅被視為其iOS
對應程序的擴展,因此您不能使用AppGroups
在兩者之間共享數據。
您應該在watchOS2+
上使用WatchConnectivity
框架在watchOS
和iOS
應用之間共享數據。
有關更多信息,請參見《 WatchKit編程指南》中的“ 共享數據”部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.