OGeek|极客世界-中国程序员成长平台

标题: ios - UILocalnotification 未在 iOS7 中显示 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:33
标题: ios - UILocalnotification 未在 iOS7 中显示

也许我遗漏了一些东西,但据我所知,我做得对。我正在尝试安排本地通知,但它似乎永远不会显示。我运行应用程序,然后点击主页按钮。 15 秒后,角标(Badge)更新为 1,但我从未看到警报。

我在 View Controller 的 viewDidLoad 中的代码是:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
NSDate *currentDate = [NSDate date];
NSDate *targetDate = [currentDate dateByAddingTimeInterval:15]; //15 seconds
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = targetDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = @"Body!";
localNotification.alertAction = @"Action!";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

如果应用程序正在运行,我确实会接到电话:

-(void)applicationUIApplication *)application didReceiveLocalNotificationUILocalNotification *)notification

有什么想法吗?据我所知,这一切都得到了正确的处理。



Best Answer-推荐答案


我发现我未能注册通知。

添加这个:

    [[UIApplication sharedApplication]registerForRemoteNotificationTypes:
 UIRemoteNotificationTypeBadge |
 UIRemoteNotificationTypeAlert |
 UIRemoteNotificationTypeSound];

解决了我的问题。

关于ios - UILocalnotification 未在 iOS7 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20176867/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4