2013-11-24 40 views
2

也許我錯過了一些東西,但據我所知,我正在做這件事。我正在嘗試安排本地通知,但似乎從未顯示。我運行該應用程序,然後點擊主頁按鈕。在15秒內,徽章更新爲1,但我從未看到警報。UILocalnotification沒有在iOS7中顯示

在我的視圖控制器的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)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 

任何想法?據我所知,這是所有正確處理。

+0

任何在您的應用程序的通知設置? – Wain

+0

我檢查了,我甚至沒有看到我的應用程序列出。對於本地通知,我是否必須像使用遠程通知一樣請求權限? – SonnyBurnette

+0

就是這樣。我必須註冊通知。 – SonnyBurnette

回答

4

我發現我未能註冊通知。

添加此:

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

解決了我的問題。

相關問題