Cannot receive push notification when application is not running

I created an iphone app with push notification function. The server is working well, and I could be notified when the application is running in the foreground. Function

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 

is called and then a notification appears. However, when I press the home key, I brought the application to the background or killed it on the taskbar. I cannot receive notifications in the notification area or in any pop-up window.

Does anyone know the reason? Thanks

+4
source share
1 answer

You can use...

 -(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { if (launchOptions != nil) { NSMutableDictionary *dic = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]; NSMutableDictionary *dicItem = [dic objectForKey:@"aps"]; NSString *itemNotification = [dicItem objectForKey:@"alert"]; }else if (launchOptions == nil){ NSLog(@"launch ,,, nil"); } ...//code something } 

itemNotification is an item on notification barges. Enjoy!

+1
source

All Articles