Error when setting UserInfo in UILocalNotification

旧时模样 提交于 2019-12-06 15:03:23

问题


I'm trying to attach an NSManagedObjectID to a UILocalNotification but keep getting the error: Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType')

Here's my code (taskID is an NSManagedObjectID):

// Create the new notification
UILocalNotification *newNotice = [[notificationClass alloc] init];
[newNotice setFireDate:date];
[newNotice setTimeZone:[NSTimeZone defaultTimeZone]];
[newNotice setAlertBody:@"Test text"];

// Add the object ID to the userinfo
NSDictionary *myUserInfo = [NSDictionary dictionaryWithObject:taskID forKey:@"TaskID"];
newNotice.userInfo = myUserInfo;

taskID is passed into the function with this code (first parameter):

addNotification([task objectID], [task taskname], [task taskexpiry]);

task is an NSManagedObject and that code has been tested and working fine for a long time.

From everything I've read this should work. Any help would be greatly appreciated.

Jason


回答1:


The userInfo must be a valid property list. See What is a Property List?. NSManagedObjectID is not any of the types allowed in a property list.

Try using [[taskID URIRepresentation] absoluteString] as your userInfo. You'll have to use -[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:] later to turn it back into an NSManagedObjectID.



来源:https://stackoverflow.com/questions/7919839/error-when-setting-userinfo-in-uilocalnotification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!