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
任何想法?據我所知,這是所有正確處理。
任何在您的應用程序的通知設置? – Wain
我檢查了,我甚至沒有看到我的應用程序列出。對於本地通知,我是否必須像使用遠程通知一樣請求權限? – SonnyBurnette
就是這樣。我必須註冊通知。 – SonnyBurnette