iOS推送NotificationServiceExtensio

2023-05-09  本文已影响0人  iOS_zy

这篇文章写的很详细,有需要的可以去参考
这篇文章是作者使用极光推送实现的

我使用的是Firebase推送功能,简称FCM
FCM文档链接

- (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];
}

说白了。就一句话的事。
但是OC中引用三方库必须要引用头文件,Swift也一样,或许会用到Bridging Header桥接文件

#import "FirebaseMessaging.h"

但是引用后发现找不到。重点来了。


image.png

类似上图这样。需要在podfile中配置你的NotificationServiceExtension
我的是这样的:

target 'ZY' do
pod 'Firebase/Messaging'
end

然后就可以了。撒花✿✿ヽ(°▽°)ノ✿

上一篇 下一篇

猜你喜欢

热点阅读