ios - iPhone 和 Apple Watch 应用程序之间的核心数据共享

标签 ios swift core-data apple-watch

我需要在我的 Apple Watch 应用程序和 iPhone 应用程序之间共享使用 Core Data 存储的数据。我发现我需要从以下 repo Apple Watch and Core Data 创建一个相同的框架

我还从 Raywenderlich 那里找到了以下代码来共享核心数据:

let kMyAppGroupName = "com.raywenderlich.mywatchapp.container"
var sharedContainerURL: NSURL? = NSFileManager.defaultManager().
 containerURLForSecurityApplicationGroupIdentifier(kMyAppGroupName)
 if let sharedContainerURL = sharedContainerURL {
 let storeURL = sharedContainerURL.URLByAppendingPathComponent("MyCoreData.sqlite")
 var coordinator: NSPersistentStoreCoordinator? = 
NSPersistentStoreCoordinator(managedObjectModel:self.managedObjectModel) coordinator?.addPersistentStoreWithType(NSSQLiteStoreType, 
configuration: nil,
URL: storeURL,
options: nil,
error: nil)
}

我已经使用 Core Data 完成了应用程序的 iPhone 部分,但我无法与 Apple Watch 应用程序共享它。任何人都可以建议一种方法,以便我可以将当​​前的核心数据存储扩展到 Apple Watch 应用程序吗?

最佳答案

您可以使用方法 openParentApplication:reply: 来检索该信息:

Check Apple documentation

关于ios - iPhone 和 Apple Watch 应用程序之间的核心数据共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29601207/

相关文章:

iphone - 将数据发布到 http iPhone

ios - 如何使用 StageWebView 关闭 Air for iOS 中的原生视频播放器

ios - swift 中的循环进度

来自可选 Double 的 Swift 字符串

ios - 此类对于键 itemname 不符合键值编码

ios - 核心数据以一对多关系保存在后台

ios - 更改 timeAgo 使系统过期

ios - 如何在tableview Cell中设置tableView的自动高度?

ios - 带有 iOS 粗体文本设置的条形按钮项目色调颜色

ios - 如何从数组元素中删除括号