如何应对推送通知视图,如果应用程序已经在后台运行 [英] How to respond to push notification view if app is already running in the background

查看:155
本文介绍了如何应对推送通知视图,如果应用程序已经在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常简单的我想做的事情。我的数据的自定义一块附加到我在处理一些推送通知

I have something fairly simple I want to do. I attach a custom piece of data to some push notifications that I handle in

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

我期待在 UIApplicationLaunchOptionsRemoteNotificationKey 并哎preSTO它就在那里。

I look for the UIApplicationLaunchOptionsRemoteNotificationKey and hey presto there it is.

如果我的应用程序正在启动的第一次方法只被调用。我如何读取相同的密钥,如果我的应用程序已经在后台运行时通报进来,用户pressed通知上的查看按钮?我想送他们到上面有该数据开放特定视图控制器,因为我做,如果应用程序正在启动首次从通知一样。

That method only gets called if my app is being launched for the first time. How do I read that same key if my application is running in the background already when the notification comes in and the user pressed the 'View' button on the notification? I want to send them to a particular view controller with that data open on it, the same as I do if the app is being launched for the first time from the notification.

推荐答案

看看应用程序:didReceiveRemoteNotification:fetchCompletionHandler: iOS中7及更高版本。

Check out application:didReceiveRemoteNotification:fetchCompletionHandler: in iOS 7 and later.

该方法应用程序:didReceiveRemoteNotification:是,如果您的应用程序在前台运行调用。它也是,如果您的应用程序在后台运行,并呼吁用户与你的推送通知从事(从而使您的应用程序活动)。

The method application:didReceiveRemoteNotification: is called if your app is running in the foreground. It also is called if your app is running in the background and the user engages with your push notification (thus making your app active).

所以,真正的问题是如何确定应用程序是在前台或者如果它通过与您的推送通知参与用户激活。

So, the real question is how to determine if the app was in the foreground or if it was made active by the user engaging with your push notification.

它看起来像<一个href=\"http://stackoverflow.com/questions/5056689/didreceiveremotenotification-when-in-background/5056935#5056935\">this回答的问题<一href=\"http://stackoverflow.com/questions/5056689/didreceiveremotenotification-when-in-background\">didReceiveRemoteNotification当在后台有钥匙:

It looks like this answer to the question didReceiveRemoteNotification when in background has the key:

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

You can tell whether your app was just brought to the foreground or not in application: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
    ...
}

这篇关于如何应对推送通知视图,如果应用程序已经在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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