小编PTC*_*CHR的帖子

NSUserDefaults返回null

可以UILocalNotification存放NSUserDefaults吗?

我试图获取值但它总是返回null.

这是尝试获取值的方法

-(IBAction)doneClicked:(id)sender
{
    NSUserDefaults *prefx = [NSUserDefaults standardUserDefaults];
    UILocalNotification *oldNotifObj = [prefx objectForKey:@"NotificationObject"];
    NSLog(@"oldNotifObj = %@",oldNotifObj);

    NSLog(@"enable notification");
    if (oldNotifObj == nil)
    {
        [self addNotification];
        NSLog(@"add a new one");
    }
    else
    {
        //if notification exist, remove old one, and add new one.
        [self removeNotification:oldNotifObj];
        [prefx setObject:nil forKey:@"NotificationObject"];
        [self addNotification];
        NSLog(@"remove old notification and add a new one");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是addNotification方法

-(void)addNotification
{
    //set the notification
    UILocalNotification *localNotif = [[UILocalNotification alloc]init];
    localNotif.fireDate = …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsuserdefaults ios uilocalnotification

0
推荐指数
1
解决办法
707
查看次数