Reputation:
How iOS behaves when we implement both didReceiveRemoteNotification as well as UNUserNotificationCenterDelegate method -
optional public func userNotificationCenter(_ center:
UNUserNotificationCenter, didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Swift.Void)
As per documentation didReceiveRemoteNotification is deprecated but if app has implemented both delegate method, which one get call for iOS 10 app as well as iOS 9 app on XCode 8 (swift 3)?
Upvotes: 12
Views: 3023
Reputation: 2698
Basically you are asking two questions,
Answering #1 (according to Apple docs):
Deprecated:
application(:didReceiveRemoteNotification:)
For remote-silent notifications:
application(:didReceiveRemoteNotification:fetchCompletionHandler:)
For remote-not-silent notifications:
When app is on background: userNotificationCenter(:didReceive:withCompletionHandler:)
When app is on foreground: userNotificationCenter(:willPresent:withCompletionHandler:)
When app will be launched from notification (look for the notification on launchOptions?[.remoteNotification]
): application(:didFinishLaunchingWithOptions:)
Answering #2:
If you implement UNUserNotificationCenterDelegate
methods, application(:didReceiveRemoteNotification:fetchCompletionHandler:)
will not be called for remote-not-silent notifications.
application(:didReceiveRemoteNotification:fetchCompletionHandler:)
will be called only for remote-silent notifications.
If you are wondering why, you can take a look a this article
Upvotes: 26