iphone - UILocalNotification 没有出现在 iOS7 中

标签 iphone objective-c ios6 ios7 uilocalnotification

我在我的项目中使用 UILocalNotification。我的代码:

        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.fireDate = event.date;
        notification.timeZone = [NSTimeZone systemTimeZone];        

        notification.hasAction = YES;
        notification.soundName = UILocalNotificationDefaultSoundName;
        [notification setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber+1];

        notification.alertBody = @"test alert body";

        notification.repeatInterval = NSDayCalendarUnit;

        NSLog(@"SCHEDULED NOTIFICATION  = %@", notification);

        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

在应该出现通知的时候,什么也没有发生,但应用程序的徽章图标值得到 +1。对于 iOS6,它工作正常。哪里会出问题?

更新 在我的应用程序运行和关闭时,我没有收到任何关于通知的警报。唯一的徽章号码正在改变。

最佳答案

如果您在前台运行它,通常会丢失 didReceiveLocalNotification:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary]   objectForKey:@"CFBundleName"]
                                                        message:notification.alertBody
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];

    [alertView show];

    // Reset badges if you want
    application.applicationIconBadgeNumber = 0;
}

关于iphone - UILocalNotification 没有出现在 iOS7 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19002506/

相关文章:

ios - 当 2 个选项卡并排共享同一个 tableView 时,UITableView 会产生额外空间

javascript - 如何突出显示 UIWebView 中第一次出现的字符串?

ios - 如何在 ios 中以编程方式获取设备序列号?

objective-c - 区分对同一委托(delegate)方法的调用

ios - iPhone 6 和 iPhone 6 Plus 模拟器在哪里存储其数据?

iphone - 以编程方式更改按钮状态

objective-c - 两根手指点击 UIButton

iOS6测试版和继续开发

ios - 有没有办法在原生 iOS 应用程序中完全控制浏览器?

iphone - Objective-C 测试框架