简体   繁体   English

UILocalnotification在iOS7中未显示

[英]UILocalnotification not showing in iOS7

Maybe I'm missing something but as far as I can tell, I am doing this right. 也许我错过了一些东西,但据我所知,我做的很好。 I am trying to schedule a local notification but it seems to never show. 我正在尝试安排本地通知,但它似乎从未显示。 I run the app, then hit the home button. 我运行该应用程序,然后单击主页按钮。 In 15 seconds, the badge updates to 1 but I never see an alert. 在15秒内,徽章更新为1,但我再也没有看到警报。

The code I have in my view controller's viewDidLoad is: 我在视图控制器的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];

If the app is running, I do indeed get a call to: 如果应用程序正在运行,我确实会接到以下电话:

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

Any ideas? 有任何想法吗? As far as I can tell, this is all being handled correctly. 据我所知,这一切都得到了正确处理。

I found that I failed to register for notifications. 我发现我没有注册通知。

Adding this: 添加:

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

Solved my issue. 解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM