在 UILocalNotification 中设置 UserInfo 时出错
我试图将 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;
taskID 使用此代码(第一个参数)传递到函数中:
addNotification([task objectID], [task taskname], [task taskexpiry]);
任务是 NSManagedObject 并且该代码经测试,长期运行良好。
从我读过的所有内容来看,这应该可行。任何帮助将不胜感激。
贾森
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
userInfo
必须是有效的属性列表。请参阅 什么是属性列表?。NSManagedObjectID
不是属性列表中允许的任何类型。尝试使用
[[taskID URIRepresentation]absoluteString]
作为您的userInfo
。稍后您必须使用-[NSPersistentStoreCoordinator ManagedObjectIDForURIRepresentation:]
将其转回NSManagedObjectID
。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 youruserInfo
. You'll have to use-[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:]
later to turn it back into anNSManagedObjectID
.