开发者

Saving localNotifications with UILocalNotifications and NSUserDefaults

开发者 https://www.devze.com 2023-02-19 12:29 出处:网络
I want to save all my scheduled localNotifications before app goes to background. I get all the localNotification from UIApplication, and I try to save like:

I want to save all my scheduled localNotifications before app goes to background.

I get all the localNotification from UIApplication, and I try to save like:

NSArray *allNot =[[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *not = [allNot objectAtIndex:0];
[[NSUserDefaults standardUserDefaults] setObject:not forKey:@"notifications"];
[[NSUserDefaults standardUserDefaults] synchronize];

Now the problem occurs.

Attempt to insert non-property value of class 'UIConcreteLocalNotification'.

When I get the local notifications from my [UIApplication sharedApplication] scheduledLocalNotifications] I obtain an array of UIConcreteLocalNotification. The problem is that the UILocalNotification is conform t开发者_如何学Co NSCoding but this object UIConcreteLocalNotification is not.

How can I fix this?


Did you cast the object retrieved using objectAtIndex: method?

UILocalNotification *not = (UILocalNotification *) [allNot objectAtIndex:0];
0

精彩评论

暂无评论...
验证码 换一张
取 消