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

前端 未结 12 1689
情深已故
情深已故 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 16:13

    You can configure your push notification's payload to call app delegate’s application:didReceiveRemoteNotification:fetchCompletionHandler: method when the app is in background. You can set some flag here so that when user launch your application next time, you can perform your operation.

    From apple’s documentation you should use this methods to download new content associated with push notification. Also for this to work, you have to enable Remote notification from Background modes and your push notification payload must contain content-available key with its value set to 1. From more info please see Using Push Notifications to Initiate a Download section from apple doc here.

    Another way is to have badge count in push notification payload. So next time your application launches you can check application badge count. If its grater than zero, perform your operation and zero/clear badge count from server also.

    Hope this helps you.

提交回复
热议问题