如果检测程序:didReceiveRemoteNotification:fetchCompletionHandler:被称为在通知中心的通知攻 [英] Detect if application: didReceiveRemoteNotification: fetchCompletionHandler: was called by tapping on a notification in Notification Center

查看:332
本文介绍了如果检测程序:didReceiveRemoteNotification:fetchCompletionHandler:被称为在通知中心的通知攻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

application: didReceiveRemoteNotification: fetchCompletionHandler:

不同于

application: didReceiveRemoteNotification:

如何?从文档:

不同于应用:didReceiveRemoteNotification:方法,这是
  所谓只有当你的应用程序正在运行时,系统调用这个方法
  无论您的应用程序的状态。如果您的应用程序被暂停或不
  运行时,系统唤醒或启动您的应用,并把它放入
  后台调用方法前运行状态。 如果用户打开
  从系统显示的警觉您的应用程序时,系统调用这个方法
  再次,让你知道用户选择了哪个通知。

Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running, the system calls this method regardless of the state of your app. If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method. If the user opens your app from the system-displayed alert, the system calls this method again so that you know which notification the user selected.

我的斗争是:我想知道,如果该方法是由用户从通知中心或从唤醒设备的无声推送通知的窃听系统显示的警觉调用。目前,据我所看到的,有区别没有明显的方式。

My struggle is: I want to know if the method was called by the user tapping an a system-displayed alert from the Notification Center or from a silent push notification that wakes up the device. Currently, as far as I can see, there is no obvious way to differentiate.

- (BOOL)application: didFinishLaunchingWithOptions:

在上面的方法跟踪的 launchOptions 的是不是一个解决方案,因为如果应用程序挂起/在后台不运行它只是调用。如果它在后台运行它不会被调用。

Tracking the launchOptions in the above method is not a solution because it's only called if the app is suspended/not running in background. If it's running in the background it doesn't get called.

推荐答案

苹果文档是有点混乱

application: didReceiveRemoteNotification: fetchCompletionHandler:  

如果您的应用程序支持远程通知后台模式使用(即你正在做BackgroundFetch。)

is used if your application supports the remote-notification background mode (ie you're doing BackgroundFetch.)

application: didReceiveRemoteNotification:  

当操作系统接收到一个RemoteNotification和应用程序运行时被调用(背景/暂停或前台。)结果
您可以检查UIApplicationState,看是否应用程序被用户带到前台(上通知攻丝)或已在运行的时候通知用武之地。

is called when the OS receives a RemoteNotification and the app is running (in the background/suspended or in the foreground.)
You can check the UIApplicationState to see if the app was brought to foreground by the user (tapping on notification) or was already running when notification comes in.

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
      UIApplicationState state = [application applicationState];
        // user tapped notification while app was in background
    if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) {
         // go to screen relevant to Notification content
    } else {
         // App is in UIApplicationStateActive (running in foreground)
         // perhaps show an UIAlertView
    }
}

这篇关于如果检测程序:didReceiveRemoteNotification:fetchCompletionHandler:被称为在通知中心的通知攻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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