iosapple-push-notificationsunnotificationserviceextension

Is it possible to get apns-collapse-id in the notification service extension?


I am trying to access to the apns-collapse-id to change the content of the notification based on some conditions. Can the apns-collapse-id be accessed in the extension?


Solution

  • Found the answer pretty immediately after posting this.

    identifier is the property you are looking for.

    From the docs:

    Use this string to identify notifications in your app. For example, you can pass this string to the removePendingNotificationRequests(withIdentifiers:) method to cancel a previously scheduled notification. ...

    For local notifications, this property is set to the value passed to the request’s initializer (see the init(identifier:content:trigger:) method). For remote notifications, it is set to the value of the apns-collapse-id key that you specified in the APNs request header when generating the remote notification. If no value is set, the system automatically assigns an identifier.