2011-10-27 31 views
0

我正在尝试将NSManagedObjectID附加到UILocalNotification但仍然收到错误: 属性列表格式无效:200(属性列表不能包含'CFType'类型的对象)在UILocalNotification中设置UserInfo时出错

这是我的代码(taskID是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通过此代码传递到函数中(第一个参数):

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

任务是一个NSManagedObject,该代码已经过测试并且工作正常了很长时间。

从我读过的一切都应该可行。任何帮助将不胜感激。

Jason

+0

发布定义和实例化taskID的代码,机会就在于问题所在。 – Jim

+0

在发布taskID的帖子中增加了一些信息。 – Jason

回答

13

userInfo必须是有效的属性列表。见What is a Property List?NSManagedObjectID不是属性列表中允许的任何类型。

尝试使用[[taskID URIRepresentation] absoluteString]作为您的userInfo。您稍后必须使用-[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:]才能将其重新设为NSManagedObjectID

+0

太棒了,做到了!感谢Rob。 – Jason

相关问题