开发者

How to set NSManagedObject info in UILocalNotification.userInfo?

开发者 https://www.devze.com 2023-04-01 02:50 出处:网络
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 s

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号