且构网

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

如何应对推送通知视图,如果应用程序已经在后台运行

更新时间:2023-02-26 20:57:03

看看应用程序: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.

它看起来像this回答的问题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
    ...
}