First of all, I know that it's impossible to serialize a NSManagedObject in the userInfo.
My question is :开发者_运维问答 Imagine my app using CoreData. When I create a new NSManagedObject, I also schedule a LocalNotification (this is a toy example). Then, when the AppDelegate received the notification, I would like to know the corresponding NSManagedObject to display it.
Does somebody know a trick to handle that?
Thanks in advance. AppPié
Hmmm ... Store a unique identifier in your Core Data model, which you send in your userInfo dictionary, to be accessed and then fetched (using the uniqueID) in the app delegate.
Matt Gallagher has a great blog post about this: http://cocoawithlove.com/2008/08/safely-fetching-nsmanagedobject-by-uri.html
Essentially, ask the NSManagedObject for it's objectID, fetch the URIRepresentation of that id, and store the URI.
He also covers some of the sharp edges related to getting the NSManagedObject using the URI, so you should really just read the blog post.
精彩评论