iOS推送NotificationServiceExtension

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

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

  • 创建推送的流程可以参考置顶2个链接 ↑↑↑
    下面主要说踩坑的地方:
    NotificationService的didReceiveNotificationRequest中需要写实现代码,因为使用了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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容