didReceiveRemoteNotification在后台时 [英] didReceiveRemoteNotification when in background

查看:455
本文介绍了didReceiveRemoteNotification在后台时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样的问题已经被问了很多次,但我有一些具体的情况怎么回事。

These kind of question has been asked a number of times but i have some specific situation going on.

在我的应用程序是活动的,我收到一条PUSH消息我是能够成功地解析定制的有效载荷和等。

When my application is active and I receive a PUSH message i'm successfully able to parse the custom payloads and such.

然而,当我的应用程序是在后台和PUSH到达用户,以获得点击查看/打开按钮被叫和 didReceiveRemoteNotification didFinishLaunchingWithOptions 后调用。

However when my application is in the background and the PUSH arrives the user has to click on the 'View/Open' button in order to get the didReceiveRemoteNotification called and the didFinishLaunchingWithOptions is called after that.

我需要我的应用程序决定他们是否有在后台或SUP preSS根据一些地方设置推送消息时与UIAlert来提示用户。

I need to have my application decide if they have to prompt the user with an UIAlert when in the background or suppress the push message based on some local settings.

任何帮助将是AP preciated,

Any help would be appreciated,

推荐答案

您的应用程序需要处理所有可能的推送通知交货状态:

You app needs to handle all the possible push notification delivery states:


  • 您的应用程序是刚刚推出的

  • Your app was just launched

您的应用程序只是从背景带到前景

Your app was just brought from background to foreground

您的应用程序已经在前台运行

Your app was already running in the foreground

您不要在传递时,选择什么presentation方法用于present的推送通知,这是恩通知本身codeD(可选警报,证件号码,声音)。但既然你presumably是在应用程序和推送通知的有效载荷两者的控制,可以在有效载荷是否存在是一个警报视图和消息已经$ psented给使用者P $指定。只有在应用程序的情况下在前台已经在运行,你知道用户不只是通过警报从主屏幕启动应用程序或定期。

You do not get to choose at delivery time what presentation method is used to present the push notification, that is encoded in the notification itself (optional alert, badge number, sound). But since you presumably are in control of both the app and the payload of the push notification, you can specify in the payload whether or not there was an alert view and message already presented to the user. Only in the case of the app is already running in the foreground do you know that the user did not just launch your app through an alert or regularly from the home screen.

您可以告诉您的应用程序是否刚刚被推上前台或者不使用didReceiveRemoteNotification该位code的:

You can tell whether your app was just brought to the foreground or not in didReceiveRemoteNotification using this bit of code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateActive )
        // app was already in the foreground
    else
        // app was just brought from background to foreground
    ...
}

这篇关于didReceiveRemoteNotification在后台时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆