Notification displayed via Notification Service Extension doesn't display correctly if the iPhone is passcode protected and locked

I've got a notification service extension which is working as expected unless the user a) turns the passcode for the iPhone on and b) turns on Auto-lock and the iPhone is locked when a push arrives If auto-lock is turned on and the phone is locked but passcode is not turned on, then the notification is displayed as expected.

The iPhone displays a notification with the top line being the name of the app and the second line saying "Notification", which is neither the content within the push payload, not what is being set as the content within the extension.

There's no difference in behaviour of the extension when passcode is enabled. Adding logging to the extension I can confirm the content is being replaced and posted as expected:

      NSLog("Going to post notification title: \(notificationContent.title) subtitle: \(notificationContent.subtitle) body: \(notificationContent.body)")
        contentHandler(notificationContent)

The notificationContent is as expected and is identical when passcode is on off. Why is the iPhone displaying the notification incorrectly if passcode is turned on and the phone locked?

What will be shown of a notification when on the Lock Screen is determined by the Lock Screen Appearance setting for Notifications in general, and your app specifically. This is a user controlled setting through the Settings app, and cannot be changed or influenced by an app directly.

@Gualtier Malde  Thank you, what setting is it that affects this? I have Show Previews set to always and can't find any other setting that makes the content of the notification appear

Show previews would be the one. It is set in two places, one globally for all Notifications, and one for the specific app. If both are set to always, then the problem lies elsewhere.

You may want to confirm that the extension is not running into a problem in locked state - for example due to file access permissions, file protection levels. For example, if the extension depends on a file that is set to .completeFileProtection, then it would not be able to access it when the device is locked, and could be failing in some way.

https://developer.apple.com/documentation/uikit/protecting_the_user_s_privacy/encrypting_your_app_s_files#2928957

Notification displayed via Notification Service Extension doesn't display correctly if the iPhone is passcode protected and locked
 
 
Q