【发布时间】: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