Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS10 UNNotificationServiceExtension not called

Im implementing new iOS10 extension to use rich notifications. Im trying to test it on push notifications but is not working, I just receive a simple notification and is not going through the extension.

I did all that it's specified in the official sites and some other places:

  • I have my app up and running with push notifications and the right provisioning profile
  • I added a new target to my app, a Notification Service Extension
  • Implemented my own code (it doesn't matter really because is not even entering to the new class)
  • Also I had to set a provisioning profile for this extension, I just use one with a wildcard, I don't see any documentation specifying if the extension target has to enable push notifications capability, in that case I would need a specific provisioning for this one, at the moment I just use a wildcard prov, anyway it matches (it must match) the profile I use in the app target, and push notifications capability is enabled for the app target only.
  • I added UNNotificationExtensionCategory and NSExtensionPointIdentifier. Also Im sending the category as part of the push payload from the server.

As I said, I get the notification but never goes through the extension. I see how the OS tries to load the extension but then throws an error with no relevant description to identify the problem:

Dec 31 21:00:00 iPhone SpringBoard(libextension.dylib)[51] <Notice>: calling plugIn beginUsing:   
Dec 31 21:00:57 iPhone pkd[86] <Notice>: assigning plug-in com.test.app.NotificationWithAttachmentExtension(1.0) to plugin sandbox   
Dec 31 21:03:57 iPhone pkd[86] <Notice>: enabling pid=51 for plug-in com.test.app.NotificationWithAttachmentExtension(1.0) 38BB5FF1-2597-42E0-B950-169DBFA80573 /private/var/containers/Bundle/Application/A8C47706-C0EC-4FB1-ABA7-0118372F6900/testapp.app/PlugIns/NotificationWithAttachmentExtension.appex   
Dec 31 21:00:53 iPhone SpringBoard(PlugInKit)[51] <Notice>: plugin com.test.app.NotificationWithAttachmentExtension interrupted   
Dec 31 21:03:56 iPhone SpringBoard(PlugInKit)[51] <Notice>: Hub connection error Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.test.app.NotificationWithAttachmentExtension" UserInfo={NSDebugDescription=connection to service named com.test.app.NotificationWithAttachmentExtension}   
Jun 29 13:33:36 iPhone SpringBoard(libextension.dylib)[51] <Notice>: PlugInKit error in beginUsing:   
Jun 17 23:33:04 iPhone SpringBoard(libextension.dylib)[51] <Notice>: killing invalid plugIn   
Dec 31 21:00:00 iPhone SpringBoard(UserNotificationsServer)[51] <Error>: Extension error whilst trying to modify push notification F502-9B36: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.test.app.NotificationWithAttachmentExtension" UserInfo={NSDebugDescription=connection to service named com.test.app.NotificationWithAttachmentExtension}   
Dec 31 21:00:00 iPhone SpringBoard(UserNotificationsServer)[51] <Notice>: [com.test.app] Saving notification F502-9B36   
Dec 31 21:00:00 iPhone SpringBoard(libextension.dylib)[51] <Notice>: completed calling plugIn beginUsing: for pid: 0  

Relevant extension .plist:

  <dict>
    <key>NSExtensionAttributes</key>
    <dict>
      <key>UNNotificationExtensionCategory</key>
      <string>attachmentCategory</string>
      <key>UNNotificationExtensionInitialContentSizeRatio</key>
      <real>1</real>
    </dict>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.usernotifications.service</string>
        <key>NSExtensionPrincipalClass</key>
        <string>$(PRODUCT_MODULE_NAME).NotificationService</string>
  </dict>

What's wrong or missing?

like image 373
Rodrigo.C Avatar asked Sep 23 '16 15:09

Rodrigo.C


People also ask

What's new in iOS 10 notification service extension?

When receiving a notification in an iOS app, you may want to be able to download content in response to it or edit the content before it is shown to the user. In iOS 10, Apple now allows apps to do this through a new Notification Service Extension .

What is unnotificationserviceextension in Salesforce?

A UNNotificationServiceExtension object provides the entry point for a notification service app extension. This object lets you customize the content of a remote notification before the system delivers it to the user. A notification service app extension doesn’t present any UI of its own.

How do I change the unnotificationserviceextension in Xcode?

The Xcode templates provide a subclass of UNNotificationServiceExtension for you to modify. You must implement the didReceive (_:withContentHandler:) method and use it to process incoming notifications. It’s also strongly recommended that you override the serviceExtensionTimeWillExpire () method.

How to send notifications to the device using the notificationserviceextension?

Select Automatically under the Launch option. Run the scheme of the extension (not the parent app). Send your device a notification. Profit. After struggling with this I finally made this work for me by just changing 2 things. The bundleID of the NotificationServiceExtension target must be a different one.


3 Answers

What also might do the trick is check your deployment target for the extension. Mine was set at 10.2 while the device I was testing on was (still) using 10.1

After altering the deployment target to 10.0 the UNNotificationServiceExtension instance was called perfectly

like image 187
basvk Avatar answered Oct 16 '22 16:10

basvk


And if you've done everything correctly, don't forget to attach it to the process.

After running the app that contains the extension:

  1. Set your breakpoint in the extension
  2. Select Debug / Attach to Process by PID or name
  3. Enter the name of the extension target
  4. Trigger the push notification
like image 25
Wojtek Dmyszewicz Avatar answered Oct 16 '22 16:10

Wojtek Dmyszewicz


Finally I have this working correctly, and this is what I remember from this issue.

1) Do not use devices with iOS10 beta version, because one of the problems I had was because I was using a beta version.

2) only the app requres APNS entitlements, this is not required for the privisoning used for the extension.

3) I was using a provisioning profile matching the id of the extension (not wildcard), anyway I cannot confirm if it works fine or not with wildcard.

4) NSExtensionAttributes are not required, just use NSExtensionPointIdentifier and NSExtensionPrincipalClass for the extension .plist. Unless you are using your own layout

5) This is working even using iOS 9 token registration methods.

6) don't forget mutable-content value in the payload coming in the push notification, this is the only mandatory value you need from the server to go through the extension.

I think this covers all the problems I had

like image 15
Rodrigo.C Avatar answered Oct 16 '22 15:10

Rodrigo.C