什么是UIApplicationLaunchOptionsRemoteNotificationKey用于?

Jan*_*Jan 4 push-notification ios

如果我理解正确的话,当应用程序未运行时收到推送(例如被杀)时,该UIApplicationLaunchOptionsRemoteNotificationKey键将用于该-[UIApplicationDelegate application:didFinishLaunchingWithOptions:]方法- 用户点击接收到的推送

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

    NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
    if(userInfo) {
        // app was not running and the user clicked on the push
    }
}
Run Code Online (Sandbox Code Playgroud)

但是......在完全相同的情况下,-[AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:]也会在前一个之后调用.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{
    // called when
    // app was not running and the user clicked on the push
    // app was running in background and user clicked on a push
    // app was running in background and a silent push was received
    // app is in foreground and a push is received
    completionHandler(UIBackgroundFetchResultNewData);
}
Run Code Online (Sandbox Code Playgroud)

所以问题是,为什么我应该使用UIApplicationLaunchOptionsRemoteNotificationKeyif如果可以在application:didReceiveRemoteNotification:fetchCompletionHandler委托中处理所有内容?我错过了什么?

干杯,

一月

Jos*_* B. 6

如果应用程序被终止并且用户点击通知中心的推送通知,则launchingOptions字典包含UIApplicationLaunchOptionsRemoteNotificationKey以便您可以调整应用启动逻辑.在以前的iOS版本中没有application:didReceiveRemoteNotification: fetchCompletionHandler:launchingOptions词典来自application:didFinishLaunchingWithOptions:唯一可以在应用程序启动时处理远程通知的地方.

我的猜测是application:didFinishLaunchingWithOptions:出于兼容性原因包含UIApplicationLaunchOptionsRemoteNotificationKey.