简体   繁体   English

iPhone和Apple Watch应用之间的核心数据共享

[英]Core data sharing between iPhone and Apple Watch apps

I need to share data stored using Core Data between my Apple Watch app and iPhone app. 我需要在Apple Watch应用程序和iPhone应用程序之间共享使用Core Data存储的数据。 I found that I need to create a framework for the same from the follwing repo Apple Watch and Core Data 我发现我需要根据后续的Apple Watch和Core Data创建一个框架

Also I've found the following code from Raywenderlich to share Core Data: 我还从Raywenderlich找到了以下代码来共享Core Data:

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)
}

I've already done the iPhone part of the app using Core Data but I fail to share it with Apple Watch app. 我已经使用Core Data完成了该应用程序的iPhone部分,但未能与Apple Watch应用程序共享。 Can anyone suggest a way so that I can extend my current Core Data store to the apple watch app? 谁能建议一种方法,以便将当前的Core Data存储扩展到Apple Watch应用程序?

You could use the method openParentApplication:reply: to retrieve that information: 您可以使用openParentApplication:reply:方法检索该信息:

Check Apple documentation 查看Apple文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM