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

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

本文介绍了当应用程序在前台运行时收到iOS推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解,当应用程序正在运行或在前台并收到推送通知时,应用程序不应显示任何警报,但应用程序代理将调用 didReceiveRemoteNotification 委托方法,我应该处理该回调中的推送通知。

From my understanding, when app is running or in the foreground and a push notification is received, the app should NOT show any alert but the app delegate will call the didReceiveRemoteNotification delegate method and I should handle the push notification in that callback.

当应用程序在后台时,推送通知应该只显示警告/横幅。

The push notification should ONLY display alerts/banners when the app is in the background.

然而,我们的应用程序在应用程序运行时或在某个时间(而不是所有时间)在前台获得推送通知警报。我想知道它是否是iOS 7中的新功能(我从未听说过这个)或是因为我使用 UrbanAirship 来使用iOS应用程序的推送通知用户的别名。该应用程序将在运行时显示推送警报并在 didReceiveRemoteNotification 中运行回调。

However, our app gets push notification alert with an OK button when the app is running or in the foreground sometime, not all of the time. I'm wondering if it is something new in iOS 7 (I have never heard of this) or is it because I'm using UrbanAirship for push notification for our iOS app using alias of the user. The app will display the push alert when running and run the callback in didReceiveRemoteNotification.

抓住我的头。有谁知道为什么?

Scratching my head over this. Does anyone know why?

推荐答案

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

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
}

这篇关于当应用程序在前台运行时收到iOS推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:12