简体   繁体   中英

cannot receive push notification when app is not running

I've created an iphone app with push notification feature. The server works well and I could receive the notification when app is running in foreground. The function

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

is called then notification arrives. However, when I press the home key, brought the app into background or kill it in the task bar. I cannot receive any notification, neither in the notification area or any popup.

Anyone knows the reason? Thanks

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 in Notification barge. Have fun!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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