I have an iOS app which uses Notification Service Extension (NSE) to update/enhance an incoming remote notification.
I have added push notification capability and enabled remote notification in Background Modes. During startup, I'm requesting user's authorization, registering my notification category - MEETING_INVITE (which I would use in payload), registering with APNs for a device token. I don't have any app server... but was able to test using the command line way.
The userNotification(_:didReceive:withCompletionHaneler:) and userNotification(_:willPresent:withCompletionHandler:) are implemented to handle notifications. I tested with a normal notification and this entire setup worked fine.
Now, I want to use a Notification Service Extension to enhance an incoming notification. I have the following project structure:
TWNotificationServiceExtension is the NSE. I want to group all notification related code in a library, called TWNotifications. The didReceive(_:withContentHandler:), which is the entry point of the NSE is implemented in the TWNotifications library. The default file in the NSE i.e., TWNotificationServiceOld.swift is fully commented (as I'm attempting to move all its contents to the library). The extension target, TWNotificationServiceExtension, has TWNotifications as a 'Target Dependency' and 'Link Binary with Libraries' in Xcode build phases settings.
I have also updated the info.plist file of the extension to use the class in TWNotifications library as the extension's principal class (as shown below)
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>TWNotifications.TWNotificationService</string>
</dict>
But it never works. The extension is completely ignored and the notification payload is displayed without any modification. I've also checked the logs and the extension is not invoked.
I'm using the following json payload and the corresponding curl command to test notifications
{
"aps": {
"category": "MEETING_INVITE",
"mutable-content": 1,
"alert": {
"title": “Encrypted title”,
"body": “Encrypted body”
}
},
"MEETING_ORGANIZER": “El Diablo”
}
curl -v --header "apns-topic: $TOPIC" --header "apts-push-type: alert" --header "authorization: bearer $AUTHENTICATION_TOKEN" --data '{"aps": {"category": "MEETING_INVITE","mutable-content": 1,"alert": {"title": "Encrypted title","body": "Encrypted body"}},"MEETING_ORGANIZER": "El Diablo"}' --http2 https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN}
Why is this not working? Can I not move the entry point function outside the extension. It feels possible because I only have to mention the appropriate class in the info.plist of the extension and there's no restriction mentioned in the Apple documentation.