【问题标题】:Notification service extensions not working for iOS with react-native-firebase通知服务扩展不适用于带有 react-native-firebase 的 iOS
【发布时间】:2020-10-29 16:10:24
【问题描述】:

我已将类别添加到我的扩展 info.plist。还在有效负载中传递相同的类别。 为 react-native 项目 iOS 原生端添加了通知服务扩展。

扩展列表:-

    <key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>UNNotificationExtensionCategory</key>
        <string>ACTION_BUTTON</string>
    </dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.usernotifications.service</string>
    <key>NSExtensionPrincipalClass</key>
    <string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>

扩展包ID:-

myprojectbundleid.extension

扩展代码:-

#import "NotificationService.h" #import "RNFirebaseMessaging.h"

@interface NotificationService()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:   (void (^)(UNNotificationContent * _Nonnull))contentHandler {
  NSLog(@"=======NotificationService");
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    // Modify the notification content here...
    self.bestAttemptContent.title = @"modified title";
   [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];

      self.contentHandler(self.bestAttemptContent);
}

- (void)serviceExtensionTimeWillExpire {
   // Called just before the extension will be terminated by the system.
   // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
    self.contentHandler(self.bestAttemptContent);
}

@end

有效载荷

{
"mutable-content" : 1,
   "notification": { 
        "title":"Take score",
        "body": "Take your score",
        "sound": "default",
        "click_action":"ACTION_BUTTON",
        "mutable_content": 1
   },
    "apns":{
      "payload": {
         "aps": {
            "mutable-content": 1,
             "click_action": "ACTION_BUTTON",
             "category": "ACTION_BUTTON"
         }
       }
    },  
    "to":"tokentosend",
    "data":{ 
       "channel_id": "channel_id",
        "title":"You have a new message12",
        "body": "hi",
        "sound": "default"
      }
 }

任何建议都会有所帮助。

【问题讨论】:

    标签: ios firebase react-native push-notification react-native-firebase


    【解决方案1】:

    您的财产mutable-content 必须是mutable_content。同时删除self.contentHandler(self.bestAttemptContent); 末尾的@interface NotificationService

    你也必须知道你的层次包标识符必须是这种格式:

    MainApp=> org.testing.app, Service => org.testing.app.service
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      • 2017-02-01
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多