在UILocalNotification中设置UserInfo时出错

Jas*_*son 0 objective-c userinfo uilocalnotification

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

这是我的代码(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;
Run Code Online (Sandbox Code Playgroud)

taskID通过此代码传递给函数(第一个参数):

addNotification([task objectID], [task taskname], [task taskexpiry]);
Run Code Online (Sandbox Code Playgroud)

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

从我读过的一切来看,这应该有效.任何帮助将不胜感激.

贾森

rob*_*off 13

本userInfo必须是有效的属性列表.请参阅什么是物业清单?. NSManagedObjectID不是属性列表中允许的任何类型.

尝试使用[[taskID URIRepresentation] absoluteString]你的userInfo.您将不得不-[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:]稍后使用它将其变回NSManagedObjectID.