iOS push notification: how to detect if the user tapped on notification when the app is in background?

前端 未结 12 1691
情深已故
情深已故 2020-11-29 15:43

There are a lot of stackoverflow threads regarding this topic, but I still didn\'t find a good solution.

If the app is not in the background, I can check launc

12条回答
  •  感动是毒
    2020-11-29 15:56

    OK I finally figured out.

    In the target settings ➝ Capabilities tab ➝ Background Modes, if you check "Remote Notifications", application:didReceiveRemoteNotification: will get triggered as soon as notification arrives (as long as the app is in the background), and in that case there is no way to tell whether the user will tap on the notification.

    If you uncheck that box, application:didReceiveRemoteNotification: will be triggered only when you tap on the notification.

    It's a little strange that checking this box will change how one of the app delegate methods behaves. It would be nicer if that box is checked, Apple uses two different delegate methods for notification receive and notification tap. I think most of the developers always want to know if a notification is tapped on or not.

    Hopefully this will be helpful for anyone else who run into this issue. Apple also didn't document it clearly here so it took me a while to figure out.

提交回复
热议问题