【问题标题】:Error when setting UserInfo in UILocalNotification在 UILocalNotification 中设置 UserInfo 时出错
【发布时间】:2011-10-27 17:23:35
【问题描述】:

我正在尝试将 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]);

task 是一个 NSManagedObject 并且该代码已经过测试并且可以正常运行很长时间。

从我读过的所有内容来看,这应该可以。任何帮助将不胜感激。

杰森

【问题讨论】:

  • 发布定义和实例化taskID 的代码,很可能这就是问题所在。
  • 在帖子中添加了更多关于 taskID 来自何处的信息。

标签: objective-c uilocalnotification userinfo


【解决方案1】:

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

尝试使用[[taskID URIRepresentation] absoluteString] 作为您的userInfo。稍后您必须使用-[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:] 将其转回NSManagedObjectID

【讨论】:

  • 太棒了,做到了!谢谢罗伯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多