iOS - Push notification alert is not shown when the app is running

前端 未结 7 631
死守一世寂寞
死守一世寂寞 2020-12-12 15:45

I\'ve integrated push notifications in my app. Users will receive push notification to join a group. When the user clicks Join, I\'ve to handle something in

7条回答
  •  误落风尘
    2020-12-12 16:16

    I used code like this in my application delegate to mimic the notification alert when the app was active. You should implement the appropriate UIAlertViewDelegate protocol method(s) to handle what happen when the user taps either of the buttons.

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    
      UIApplicationState state = [application applicationState];
      if (state == UIApplicationStateActive) {
          NSString *cancelTitle = @"Close";
          NSString *showTitle = @"Show";
          NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Some title"
           message:message 
           delegate:self 
           cancelButtonTitle:cancelTitle 
           otherButtonTitles:showTitle, nil];
          [alertView show];
          [alertView release];
      } else {
        //Do stuff that you would do if the application was not active
      }
    }
    

提交回复
热议问题