你能帮帮我吗?
我正在设置一个UILocalNotification,当我试图设置它的userInfo字典时,它崩溃了。fetchedObjects包含88个对象。
代码如下:
NSDictionary* myUserInfo = [NSDictionary dictionaryWithObject: fetchedObjects forKey: @"textbody"];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
// défining the interval
NSTimeInterval oneMinute = 60;
localNotif.timeZone = [NSTimeZone localTimeZone];
NSDate *fireDate = [[NSDate alloc]initWithTimeIntervalSinceNow:oneMinute];
localNotif.fireDate = fireDate;
localNotif.userInfo = myUserInfo; //this is the line that crashes the app
[fetchedObjects release];控制台给了我这样的信息:
Property list invalid for format: 200
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unable to serialize userInfo: (null)'有什么想法吗?
发布于 2011-01-09 18:48:33
听起来像是您的userInfo字典中有一些对象没有实现NSCoding协议。该字典中的所有内容都必须能够写入“磁盘”,因为当通知触发时,您的应用程序可能没有运行。如果里面有不能序列化的东西,这就是结果。
发布于 2011-08-30 03:08:27
实际上,即使使用符合NSCoding的对象,UILocalNotification也会在调用setUserInfo时抛出NSInvalidArgumentException。显然,UILocalNotification对属性列表类型有更严格的解释,其中只允许属性列表编程指南中指定的库存对象。您可以通过使用NSKeyedArchiver将符合NSCoding的自定义对象序列化为NSData实例来解决此问题,该实例可以安全地传递给userInfo字典中的UILocalNotification。
https://stackoverflow.com/questions/4637179
复制相似问题