Test Rich Notifications in Simulator
Asked Answered
P

1

8

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];
}
Pons answered 27/3, 2020 at 14:49 Comment(1)
Xcode 14 has a fix...Syrinx
S
13

Possible Xcode 14 workaround

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.

Based on docs starting from Xcode14:

  • remote notification sent to the simulator: will be passed to the Notification Service Extension.
  • locally simulated notification sent to the simulator: will NOT passed to the Notification Service Extension.

OLD Answer

See older revision of this answer for Older Xcode versions up to Xcode 13.

Syrinx answered 27/3, 2020 at 18:37 Comment(7)
FYI This is still not fixed in 12.5 Beta.Syrinx
Another FYI, still does not seem to resolved in 13.4.1Twelvemo
After investing hours on this, found out Service extensions are not supported on simulator. It worked while testing on real device.Butler
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.Dowel
@Dowel I think it actually depends. see my updated answerSyrinx
I just tested this, using Xcode 15. I sent a mutable notification from the "Push Notifications" part of this dashboard. The aps dictionary should contain a "mutable-content" key, with the integer value of 1. I could edit the received contents in the SceneDelegate, and the edits showed in the simulator.Clynes
@Clynes Thanks for mentioning it here. I updated my answerSyrinx

© 2022 - 2024 — McMap. All rights reserved.