如果我理解正确,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
}
}
但..在完全相同的情况下,-[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);
}
所以问题是,如果可以在UIApplicationLaunchOptionsRemoteNotificationKey
代理中处理所有内容,为什么要使用application:didReceiveRemoteNotification:fetchCompletionHandler
?我错过了什么吗?
欢呼声,
扬
答案 0 :(得分:6)
如果应用程序被终止且用户点击通知中心的推送通知,则launchingOptions
字典包含UIApplicationLaunchOptionsRemoteNotificationKey
,以便您可以调整应用启动逻辑。
在以前的iOS版本中,来自application:didReceiveRemoteNotification: fetchCompletionHandler:
的{{1}}和launchingOptions
词典是唯一可以在应用启动时处理远程通知的地方。
我的猜测是application:didFinishLaunchingWithOptions:
出于兼容性原因包含UIApplicationLaunchOptionsRemoteNotificationKey。
答案 1 :(得分:0)
此键的存在表示可以让应用程序处理远程通知。此键的值是包含远程通知的有效负载的NSDictionary。