添加图像密钥时在 ios 通知标题中得到 [修改]

getting [modified] in ios notification title when adding image key

当在通知负载中添加图像参数时,我在 ios 设备通知的标题中得到 [修改]。另外,我尝试从 firebase 发送通知,但在添加图像时遇到了同样的问题。

注意:它在 android 设备上运行良好。

例如: 如果我设置标题“Hello”,那么它会在 ios 通知中显示“Hello [modified]”。

“[modified]”字符串似乎是根据 documentation for sending images in iOS FCM notifications 中的这个示例 NotificationService.m 文件添加的:

    @interface NotificationService () <NSURLSessionDelegate>
    @property(nonatomic) void (^contentHandler)(UNNotificationContent *contentToDeliver);
    @property(nonatomic) UNMutableNotificationContent *bestAttemptContent;
    @end
    
    @implementation NotificationService
    
    - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
        self.contentHandler = contentHandler;
        self.bestAttemptContent = [request.content mutableCopy];
    
        // Modify the notification content here as you wish
        self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]",
        self.bestAttemptContent.title];
    
      // Call FIRMessaging extension helper API.
      [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent
                                                withContentHandler:contentHandler];
    
    }
    ...

解法:

使用 XCode 打开您的 iOS 项目并打开 NotificationService.m 文件并删除此行:

        // Modify the notification content here as you wish
        self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]",
        self.bestAttemptContent.title];