且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用在前台运行时收到 iOS 推送通知

更新时间:2022-12-27 11:13:35

当应用程序在前台时,它不应显示任何内容.

When the App is in foreground, it should not display anything.

如果您看到 alertView,则表示您为其提供了代码.

If you see alertView, it means you provided code for it.

大致如下:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    UIApplicationState state = [application applicationState];

    if (state == UIApplicationStateActive) {
        //app is in foreground
        //the push is in your control
    } else {
        //app is in background:
        //iOS is responsible for displaying push alerts, banner etc..
    }
}

如果你已经实现了pushNotificationDelegate

[UAPush shared].pushNotificationDelegate = self;

然后覆盖,并将其留空

- (void)displayNotificationAlert:(NSString *)alertMessage
{
  //do nothing
}