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

前端 未结 7 597
死守一世寂寞
死守一世寂寞 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:35

    Here is a version which support UIAlertController

    -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    UIApplicationState state = [application applicationState];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    if (state == UIApplicationStateActive) {
    
        UIAlertController * alert=   [UIAlertController
                                      alertControllerWithTitle:notification.alertTitle
                                      message:notification.alertBody
                                      preferredStyle:UIAlertControllerStyleAlert];
    
        UIAlertAction* ok = [UIAlertAction
                             actionWithTitle:@"OK"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 [alert dismissViewControllerAnimated:YES completion:nil];
    
                             }];
    
        [alert addAction:ok];
    
        [self.navigationController presentViewController:alert animated:YES completion:nil];
    
    }
    

    }

    ** Please note my app uses self.navigationController in App Delegate, just hook on to any ViewController to present ( show ) the Alert **

    0 讨论(0)
提交回复
热议问题