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

前端 未结 12 1692
情深已故
情深已故 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:49

    Solved with Deployent target change, after lots of trial and error.

    I was experiencing the same issue with iOS Deployment Target 9.0 and 10.0, XCode Version 11.6 (11E708). - did not get any delegate method calls from tapping the notification when the app is in background.

    What solved this was changing the Target to iOS 11.0. I finally started getting the calls on notification tap from cold start and background scenarios in the UNUserNotificationCenter delegate didReceive: implementation.

    Additionally, the willReceive: now also gets the call in the foreground scenario (as expected).

    The payload I'm using is following. Note, that there's no content-available, or mutable-content set.

    {
      "aps": {
        "sound": "default",
        "badge": 1,
        "alert": {
          "body": "test",
          "title": "test"
        }
      }
    }
    

提交回复
热议问题