iOS 10多媒体推送

前言

本文只针对个推所做的总结,其他推送大同小异

正文

1.添加Notification Service Extension

选择File->New->Target->Notification Service Extension

image

选择Activate即可,如果没有弹出该选项框,需要自行添加相应的 scheme。
需要注意的点:

  • Extension 的 Bundle Identifier 不能和 Main Target(也就是你自己的 App Target)的 Bundle Identifier 相同,否则会报 BundeID 重复的错误。
  • Extension 的 Bundle Identifier 需要在 Main Target 的命名空间下,比如说 Main Target 的 BundleID 为 ent.getui.xxx,那么Extension的BundleID应该类似与ent.getui.xxx.yyy这样的格式。如果不这么做,会引起命名错误。

可以使用.NotificationService的格式

NotificationService的 Deployment Target要设置最低10.0

2.添加请求代码

之后项目中会多出一个文件夹NotificationService,其中包括一对关键文件
NotificationService.hNotificationService.m
.m中会默认有两个方法

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

当多媒体消息到达客户端后会走第一个方法,可以在其中处理资源
但是如果处理时间过长,将会进入serviceExtensionTimeWillExpire方法进行最后的紧急处理。

NotificationService文件夹中的info.plist要添加App Transport Security Settings字典类型,并增加BOOL类型的Allow Arbitrary Loads设置为YES

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 证书配置+个推应用配置略过 Xcode集成 在项目中添加 Notification Service Extensi...
    看我的大白眼阅读 7,785评论 0 4
  • 1,背景 最近项目集成客服系统涉及到推送消息, app 进行整体消息改版,所有我把项目中的推送相关的代码和逻辑整合...
    崔可一阅读 7,385评论 5 8
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,912评论 1 32
  • 介绍一下iOS10的通知新功能,用户体验的提升和开发者能够发挥的地方非常多,使得iOS更具有竞争力。 1.iOS ...
    F麦子阅读 9,455评论 3 4
  • 转载自:iOS10里的通知与推送 原文 通知和推送是一种东西么? iOS 10通知 推送 图1为通知,图2为推送也...
    路漫漫其修远兮Wzt阅读 4,613评论 0 1

友情链接更多精彩内容