iOS 10 How to set UNotificationContent threadIdentifier for remote notification

后端 未结 1 957
长情又很酷
长情又很酷 2021-01-06 10:53

TL;DR: What key needs to be set in the APNs notification payload JSON to correspond to the threadIdentifier property of the UNNotificatio

相关标签:
1条回答
  • 2021-01-06 11:31

    I discovered from a contact at Apple that the correct key to populate this property is the "thread-id" key.

    So the JSON sent to APNs is as follows:

    {
        "aps" : {
            "alert" : "Hello World!",
            "sound" : "default",
            "category" : "example-category",
            "thread-id" : "my conversation blah blah"
        }
        "custom-field" : "some value",
    }
    

    This populates the threadIdentifier property of the UNNotificationContent object accessible in your Notification Content Extension via notification.request.content.threadIdentifier.

    By setting this "thread-id" value, it means that the didReceive(_:) method of your content extension will be multiple times. First when expanding the notification initially, and again whenever a new notification arrives with the same "thread-id" value.

    I assume (hope) this will be added to the official documentation once iOS 10 is officially released.

    0 讨论(0)
提交回复
热议问题