gpt4 book ai didi

ios - 检测应用程序是否为 : didReceiveRemoteNotification: fetchCompletionHandler: was called by tapping on a notification in Notification Center

转载 作者:IT王子 更新时间:2023-10-29 07:40:52 25 4
gpt4 key购买 nike

application: didReceiveRemoteNotification: fetchCompletionHandler:

不同于

application: 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.

我的问题是:我想知道该方法是由用户从通知中心点击系统显示的警报调用的,还是由唤醒设备的静默推送通知调用的。目前,据我所知,还没有明显的区分方法。

- (BOOL)application: didFinishLaunchingWithOptions:

在上述方法中跟踪 launchOptions 不是解决方案,因为它仅在应用程序暂停/未在后台运行时调用。如果它在后台运行,则不会被调用。

最佳答案

Apple 文档有点困惑

application: didReceiveRemoteNotification: fetchCompletionHandler:  

如果您的应用程序支持远程通知后台模式(即您正在执行 BackgroundFetch。),则使用该选项。

application: didReceiveRemoteNotification:  

当操作系统收到 RemoteNotification 并且应用正在运行(在后台/暂停或在前台)时调用。
您可以检查 UIApplicationState 以查看应用程序是被用户带到前台(点击通知)还是在收到通知时已经在运行。

- (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
}
}

关于ios - 检测应用程序是否为 : didReceiveRemoteNotification: fetchCompletionHandler: was called by tapping on a notification in Notification Center,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23168345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com