Reputation: 7644
if I understand correctly, the UIApplicationLaunchOptionsRemoteNotificationKey
key is used on the -[UIApplicationDelegate application:didFinishLaunchingWithOptions:]
method when
- the push was received when the application was not running (e.g. killed)
- the user clicked on the received push
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo) {
// app was not running and the user clicked on the push
}
}
but .. in this exact same case, the -[AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:]
is also called just after the previous one.
- (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);
}
So the question is, why should I use the UIApplicationLaunchOptionsRemoteNotificationKey
if everything can be handled in the application:didReceiveRemoteNotification:fetchCompletionHandler
delegate? Did I miss something?
cheers,
Jan
Upvotes: 5
Views: 1983
Reputation: 1489
The presence of this key indicates that a remote notification is available for the app to process. The value of this key is an NSDictionary containing the payload of the remote notification.
Upvotes: 0
Reputation: 2464
In case when the app is killed and user taps on push notification in notification center, launchingOptions
dictionary contains UIApplicationLaunchOptionsRemoteNotificationKey
so that you can adjust your app start logic.
In prior iOS version there wasn't application:didReceiveRemoteNotification: fetchCompletionHandler:
and launchingOptions
dictionary from application:didFinishLaunchingWithOptions:
was the only place where you could handle remote notification on app start.
My guess is that application:didFinishLaunchingWithOptions:
contains UIApplicationLaunchOptionsRemoteNotificationKey for compatibility reasons.
Upvotes: 7