ios - How to access Core Data/CouldKit via Today Extension (iOS8) -
i have app uses core data standard apple core data stack in appdelegate. i've modified stack core data enhanced cloudkit. data synced across devices nicely. far good.
i'd add today extension app have no idea how access data. i've been reading appgroup concept read shouldn't/can't use access data today extension. figured should using cloudkit learned nsmanagedobjects converted ckrecords upon upload icloud.
how access data via icloud has been stored core data using cloudkit enhancement? data stored in icloud?
while data syncing nicely, when check in icloud dashboard no data seem exist. articles read seem addressing part of problem.
here modified core data stack i'm using in app:
// mark: - core data stack lazy var managedobjectmodel: nsmanagedobjectmodel = { // managed object model application. property not optional. fatal error application not able find , load model. let modelurl = nsbundle.mainbundle().urlforresource("appname", withextension: "momd")! return nsmanagedobjectmodel(contentsofurl: modelurl)! }() lazy var persistentstorecoordinator: nspersistentstorecoordinator? = { // persistent store coordinator application. implementation creates , return coordinator, having added store application it. property optional since there legitimate error conditions cause creation of store fail. // create coordinator , store var coordinator: nspersistentstorecoordinator? = nspersistentstorecoordinator(managedobjectmodel: self.managedobjectmodel) let documentdirectory = nsfilemanager.defaultmanager().urlsfordirectory(nssearchpathdirectory.documentdirectory, indomains: nssearchpathdomainmask.userdomainmask).last as! nsurl let storeurl = documentdirectory.urlbyappendingpathcomponent("appname.sqlite") var error: nserror? = nil var failurereason = "there error creating or loading application's saved data." let storeoptions = [nspersistentstoreubiquitouscontentnamekey:"itemscloudstore"] let url = storeurl if coordinator!.addpersistentstorewithtype(nssqlitestoretype, configuration: nil, url: url, options: storeoptions, error: &error) == nil { coordinator = nil // report error got. var dict = [string: anyobject]() dict[nslocalizeddescriptionkey] = "failed initialize application's saved data" dict[nslocalizedfailurereasonerrorkey] = failurereason dict[nsunderlyingerrorkey] = error error = nserror(domain: "your_error_domain", code: 9999, userinfo: dict) // replace code handle error appropriately. // abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development. nslog("unresolved error \(error), \(error!.userinfo)") abort() } return coordinator }() lazy var managedobjectcontext: nsmanagedobjectcontext? = { // returns managed object context application (which bound persistent store coordinator application.) property optional since there legitimate error conditions cause creation of context fail. let coordinator = self.persistentstorecoordinator if coordinator == nil { return nil } var managedobjectcontext = nsmanagedobjectcontext(concurrencytype: nsmanagedobjectcontextconcurrencytype.mainqueueconcurrencytype) managedobjectcontext.persistentstorecoordinator = coordinator return managedobjectcontext }() // mark: - core data saving support func savecontext () { if let moc = self.managedobjectcontext { var error: nserror? = nil if (moc.haschanges && !moc.save(&error)) { println("unresolved error \(error), \(error!.userinfo)") abort() } else { println("context updated") } } }
after research seems unsolved problem apple. core data , icloud don't work extensions. check out article:
https://devforums.apple.com/message/1050891#1050891
bit of bummer. let hope fix in ios9 @ least.
Comments
Post a Comment