Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

iphone - UILocalNotification crash

could you please help me ?

I'm setting up an UILocalNotification and It crashes when I try to set its userInfo dictionary. fetchedObjects contains 88 objects.

Here is the code :

    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];

and the console gives me this :

Property list invalid for format: 200
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unable to serialize userInfo: (null)'

Any idea ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Actually, even if using an NSCoding-compliant object, UILocalNotification will throw an NSInvalidArgumentException upon calling setUserInfo. The UILocalNotification apparently keeps a more stringent interpretation of property-list types, in which only the stock objects specified in the Property List Programming Guide are allowed. You can get around this by using NSKeyedArchiver to serialize your custom NSCoding-compliant object to an NSData instance, which may be safely passed to UILocalNotification in the userInfo dictionary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...