7

I am able to test the normal notifications in Simulator, but when I tried to test rich notifications nothing happens, event title is not getting updated.

Could you please assist me, how to proceed. Do I need to change any simulator settings? I am using Xcode 11.4

Sample Payload :

{
    "aps": {
        "mutable-content": 1,
        "alert": {
            "body": "Push notification body",
            "title": "Push notification title"
        }
    },
    "media-url": "https://i.imgur.com/t4WGJQx.jpg"
}

NotificationService Extension Method:

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
     self.contentHandler = contentHandler;
     self.bestAttemptContent = [request.content mutableCopy];
    
    self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]",
    self.bestAttemptContent.title];
}
mfaani
  • 33,269
  • 19
  • 164
  • 293
dsarathb
  • 71
  • 1
  • 3

1 Answers1

11

EDIT - Xcode 14 - issue still exists

Xcode 14 release notes:

Simulator now supports remote notifications in iOS 16 when running in macOS 13 on Mac computers with Apple silicon or T2 processors. Simulator supports the Apple Push Notification Service Sandbox environment. Your server can send a remote notification to your app running in that simulator by connecting to the APNS Sandbox (api.sandbox.push.apple.com). Each simulator generates registration tokens unique to the combination of that simulator and the Mac hardware it’s running on. See User Notifications for more information.

Remote Notifications support more features (like Notification Service Extensions) than locally simulated notifications using .apns payload files or the simctl push command.

OLD Answer

Looking at Xcode 11.4 release notes

Under Known Issues:

Notification Service Extensions do not work in simulated push notifications. The mutable-content key is not honored. (55822721)

I guess your fallback is to just test it by sending a real notification using a tool like PushNotifications where you need:

  • device token
  • bundle identifier
  • certificate or token
  • payload
  • selection of correct environment

I used PushNotifications myself and it worked.

mfaani
  • 33,269
  • 19
  • 164
  • 293
  • 5
    FYI This is still not fixed in 12.5 Beta. – mfaani Feb 25 '21 at 01:31
  • Another FYI, still does not seem to resolved in 13.4.1 – Kpalser Aug 26 '22 at 14:33
  • 1
    After investing hours on this, found out Service extensions are not supported on simulator. It worked while testing on real device. – Paras Gupta Jun 29 '23 at 21:18
  • 1
    As of Xcode version Version 14.3.1, you still cannot test Notification Service Extensions in the simulator. It will not honor 'mutable-content'. You can, however, test Notification Content Extensions. The simulator does honor 'category'. Yes, it is frustrating. – smakus Jul 13 '23 at 19:47
  • 1
    @smakus you’re right. I misread the docs. It’s still not fixed – mfaani Jul 14 '23 at 02:51