Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当应用程序在前台运行时,如何忽略远程通知,但在单击通知启动应用程序时如何处理远程通知?_Ios_Push Notification_Apple Push Notifications - Fatal编程技术网

Ios 当应用程序在前台运行时,如何忽略远程通知,但在单击通知启动应用程序时如何处理远程通知?

Ios 当应用程序在前台运行时,如何忽略远程通知,但在单击通知启动应用程序时如何处理远程通知?,ios,push-notification,apple-push-notifications,Ios,Push Notification,Apple Push Notifications,应用程序在前台运行时如何忽略远程通知,但在单击通知栏上的通知以启动应用程序时如何响应远程通知?当应用程序在前台运行时,通知栏中不会显示通知。通知有效负载被传递到应用程序:didReceiveMemotentification:方法,如果您需要,可以在其中忽略它 当通知到达时,应用程序在后台运行,当您打开应用程序时,也会调用application:didReceiveMemotentification:。您可以使用以下代码区分这两种情况: -(void)application:(UIApplica

应用程序在前台运行时如何忽略远程通知,但在单击通知栏上的通知以启动应用程序时如何响应远程通知?

当应用程序在前台运行时,通知栏中不会显示通知。通知有效负载被传递到
应用程序:didReceiveMemotentification:
方法,如果您需要,可以在其中忽略它

当通知到达时,应用程序在后台运行,当您打开应用程序时,也会调用
application:didReceiveMemotentification:
。您可以使用以下代码区分这两种情况:

-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if([app applicationState] == UIApplicationStateInactive)
    {
        //application was running in the background
    }
}

当您通过点击通知打开应用程序时,通知负载将传递给另一个方法,称为
应用程序:didfishlaunchingwithoptions:
,您可以在其中处理它。

我更喜欢这个组合。如果没有我在
didfishlaunchingwithoptions
中添加的功能,当应用程序第一次从通知点击启动到内存中时,通知将不会通过
didreceiveremotentification
中包含的逻辑进行深度链接

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

    // All your nice startup code

    // ...

    // Hook for notifications
    if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
        [self application:application didReceiveRemoteNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
    }
}
顺便说一句,这两个都在您的AppDelegate中

- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {

    if (application.applicationState == UIApplicationStateActive) {
        return;
    }

    // Do anything you want with the notification, such as deep linking

    // ...
}

但我发现它总是传递给应用程序:didReceiveEmotentification:method。我发现它总是在应用程序位于后台时传递给应用程序:didReceiveEmotentification:method。但是在我终止进程后,有效负载被传递到应用程序:didFinishLaunchingWithOptions:method..因此,我的问题仍然没有答案。这很酷,它是有效的。我发现应用程序:didReceiveMemoteNotify:method在应用程序IDDecomeActive:method之前运行。非常感谢!