Notification Service Extension Not working

While implementing Notification Service you come across a situation where you have implemented all the code mentioned in the tutorial and still your

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void

is not getting called. So here I present you with checkpoints and in 99% of the cases, one of the points will work. For other 1% may force be with you.

1. Check Your Target

  1. You have to run your project with the app as a target for the first time.
  2. After one successful launch stop the app and Kill it from the background by swiping up
  3. Now run your project by choosing your service as a target
    • You will be presented with a list of apps, choose your app

If you get an error in step three and you get “Application info provider returned nil” read the next point

2. Check deployment targets

Make sure your app and extension deployment targets are set lower than the device.

NOTE: For those using firebase messaging SDK. You need to keep the app deployment target and extension deployment target equal to the Firebase Messaging SDK deployment target.

3. Check Device OS

Sometimes for no definite reason service extensions don’t work on the Beta version. I would suggest testing on a device with a non-beta iOS version.

4. Check Payload

The payload should have

"mutable-content": 1

Make sure that you are registered for the category coming in payloads “category” key. You can register for a category by using

            let yourCategory = UNNotificationCategory(identifier: "identifier string same as payload", actions: [you can put actions here], intentIdentifiers: [], options: [])
            UNUserNotificationCenter.current().setNotificationCategories([yourCategory,<Its an array you can pass multiple categories.>])

5. Device Restart

I know this should be the first thing one should do but yes here we go… Restart your device.

Above I have discussed most of the things which could go wrong while implementing Notification Service Extensions but still if it doesn’t work the generic Xcode troubleshooting steps should be followed which are

  • Clean project
  • Delete derived data
  • Relaunch Xcode

Hope this article helps you. Do leave a comment.

A pat on the back !!