我在我的應用程序上使用本地通知。當它到達時,我會完美地處理通知,並且即使應用程序運行甚至沒有運行,並且當您從設備的「通知」中打開通知時,也會按通知。但是,當應用程序沒有運行,你打開直接的應用程序,然後通知屏幕不會打開,徽章號碼不會是0.我錯過了什麼?目標c的iOS本地通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (locationNotification) {
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
NotificationsViewController *vc = nil;
if (localNotif) {
//base on notification create right view controller
vc = [[NotificationsViewController alloc] init];
NSLog(@"Recieved Notification %@",localNotif);
}
else
{
//create default view controller
vc = [[NotificationsViewController alloc] init];
}
// Add the view controller's view to the window and display.
_window.rootViewController = vc;
[_window makeKeyAndVisible];
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}
return YES;
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NotificationsViewController *vc = nil;
vc = [[NotificationsViewController alloc] init];
_window.rootViewController = vc;
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
//We take the rootViewController first which is expected to be a UINavigationController in your case
}
如果您沒有從通知中打開應用程序,該應用程序不知道有通知 – jcesarmobile 2014-10-07 07:54:28
檢查applicationIconBadgeNumber如何?我做了這樣的事情,它似乎工作,但我想不是最好的辦法:if(application.applicationIconBadgeNumber> 0) NotificationsViewController * vc = nil; vc = [[NotificationsViewController alloc] init]; _window.rootViewController = vc; [_window makeKeyAndVisible]; //將圖標徽章號碼設置爲零 application.applicationIconBadgeNumber = 0; } – Katerina 2014-10-07 08:23:40
與你可以知道是否有通知,但你不能得到通知信息(消息或其他數據發送) – jcesarmobile 2014-10-07 08:45:40