Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

xcode - Test Rich Notifications in Simulator

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];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...