【发布时间】:2019-08-11 00:59:47
【问题描述】:
我正在尝试按照此处的指南进行操作:https://firebase.google.com/docs/cloud-messaging/ios/send-image
我去了New > Target > Notification Service Extension(把这个新的target嵌入到原来的target中)并粘贴在NotificationService.m:
@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 {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
// Modify the notification content here...
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
// Call FIRMessaging extension helper API.
[[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
我现在收到Use of undeclared identifier 'FIRMessaging' in NotificationService.m。
在NotificationService.m 中,我尝试导入类似于我的原始目标的AppDelegate.m,其中FIRMessaging 可用并且没有问题:
#import "NotificationService.h"
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
...
然后我得到'Firebase.h' file not found。我很困惑,因为它似乎在原始目标中工作,并且此通知服务扩展嵌入在该目标中。我试过弄乱Header Search Paths 和Framework Search Paths,但运气不佳。我做错了什么?
【问题讨论】:
-
您是否在 podfile 中为“服务扩展”添加了 Firebase?
-
哦,我不知道我的 Podfile 中还需要另一个目标!这很有效,让我克服了导入错误。现在我用
FirMessagingRemoteNotificationsProxy.m打sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead."。 -
酷。您在哪一行收到此错误?
-
NSObject<UIApplicationDelegate> *appDelegate = [[UIApplication sharedApplication] delegate];我读过 Firebase 将其升级为不使用sharedApplication: github.com/firebase/firebase-ios-sdk/pull/1503,但我被困在旧版本5.4.0上。 :C -
不,您不能从“服务扩展”访问 AppDelegate。我也尝试用它来更新推送通知的批量计数,但没有用。
标签: ios objective-c firebase react-native firebase-cloud-messaging