How to handle push notifications if the application is already running?

后端 未结 4 1060
梦谈多话
梦谈多话 2020-12-02 05:02

How do we handle push notifications if the application is already running ? I want to show an alert if the application is running (instead of a push notification al

4条回答
  •  感动是毒
    2020-12-02 05:51

    You can check for the state of the UIApplication. Just do a check like this

     - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
    {
    
        UIApplicationState state = [application applicationState];
        if (state == UIApplicationStateActive)
        {
    
                UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"xxx" message:yourMessage delegate:self cancelButtonTitle:@"Done" otherButtonTitles: @"Anzeigen", nil] autorelease];
                [alert setTag: 2];
                [alert show];
        }
        else {
            // Push Notification received in the background
        }
    }
    

提交回复
热议问题