当前位置: 首页 > news >正文

android接收富文本推送,iOS10富文本推送--NotificationServiceExtension

NotificationService文件

额外添加了一个文件管理器的字段,用来存储数据

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);

@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@property (nonatomic, strong) NSFileManager *fileMgr;

@end

@implementation NotificationService

LazyLoad

-(NSFileManager *)fileMgr{

return [NSFileManager defaultManager];

}

收到远程通知之后,在当前方法内进行处理,并生成attchment,最终回调给系统

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {

self.contentHandler = contentHandler;

self.bestAttemptContent = [request.content mutableCopy];

NSDictionary * userInfo = request.content.userInfo;

NSString * attchUrl = userInfo[@"aps"][@"image"];

NSString *exetension = [NSString stringWithFormat:@".%@",[[attchUrl componentsSeparatedByString:@"."] lastObject]];

if (attchUrl) {

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

NSURL *url = [NSURL URLWithString:attchUrl];

NSURLSessionDownloadTask *download = [session downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable tempLocation, NSURLResponse * _Nullable response, NSError * _Nullable error) {

if (!error) {

NSURL *localURL = [NSURL fileURLWithPath:[tempLocation.path stringByAppendingString:exetension]];

[self.fileMgr moveItemAtURL:tempLocation toURL:localURL error:&error];

NSError *attachmentError = nil;

UNNotificationAttachment * attachment = [UNNotificationAttachment attachmentWithIdentifier:@"photo" URL:localURL options:nil error:&attachmentError];

if (attachmentError) {

NSLog(@"%@",attachmentError);

}else if (attachment){

self.bestAttemptContent.attachments = @[attachment];

}

}else{

NSLog(@"%@",error.localizedDescription);

}

self.bestAttemptContent.categoryIdentifier = userInfo[@"aps"][@"category"];//这里设置这个类别的标识符

self.contentHandler(self.bestAttemptContent);//回调给系统

}];

[download resume];

}

}

超时,异常时调用

- (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

相关文章:

  • 围绕EMF探索(1)之存储和查询
  • android888是什么文件夹,Android资源文件及文件夹介绍
  • MEDC2007悉尼站略影-期待MEDCing之(一)
  • android 各别控件缩放,[翻译]Android单手指缩放-第二部分(Android one finger zoom tutorial – Part 2)...
  • 终于见到了马云;杭州——梦想的家园
  • notepad html 自动格式化代码,notepad++格式化html代码
  • MEDC上想看到的新技术
  • 简报a4纸的html页面,简报模板
  • web集群服务的负载均衡方案选择与实现
  • html三角形阴影css3,用CSS画一个带阴影的三角形
  • 我们为什么不外包?让专业的人做专业的事情
  • 计算机主机与硬盘连接不上,电脑主机不认硬盘了怎么处理
  • 两盆花
  • 考研专业课的计算机网络需要报班吗,计算机考研专业课需要报班吗?
  • 40km
  • [译] 理解数组在 PHP 内部的实现(给PHP开发者的PHP源码-第四部分)
  • 【跃迁之路】【735天】程序员高效学习方法论探索系列(实验阶段492-2019.2.25)...
  • 2018以太坊智能合约编程语言solidity的最佳IDEs
  • Create React App 使用
  • create-react-app做的留言板
  • CSS魔法堂:Absolute Positioning就这个样
  • css选择器
  • export和import的用法总结
  • java2019面试题北京
  • java取消线程实例
  • Java知识点总结(JavaIO-打印流)
  • orm2 中文文档 3.1 模型属性
  • PhantomJS 安装
  • Quartz实现数据同步 | 从0开始构建SpringCloud微服务(3)
  • React-redux的原理以及使用
  • Redis 中的布隆过滤器
  • Transformer-XL: Unleashing the Potential of Attention Models
  • 测试如何在敏捷团队中工作?
  • 对象管理器(defineProperty)学习笔记
  • 工程优化暨babel升级小记
  • 和 || 运算
  • 那些被忽略的 JavaScript 数组方法细节
  • 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上
  • 由插件封装引出的一丢丢思考
  • 原生js练习题---第五课
  • 数据可视化之下发图实践
  • ​总结MySQL 的一些知识点:MySQL 选择数据库​
  • (AngularJS)Angular 控制器之间通信初探
  • (Mirage系列之二)VMware Horizon Mirage的经典用户用例及真实案例分析
  • (ZT) 理解系统底层的概念是多么重要(by趋势科技邹飞)
  • (三分钟了解debug)SLAM研究方向-Debug总结
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (万字长文)Spring的核心知识尽揽其中
  • (一)kafka实战——kafka源码编译启动
  • (原創) 如何優化ThinkPad X61開機速度? (NB) (ThinkPad) (X61) (OS) (Windows)
  • (转)jQuery 基础
  • *p++,*(p++),*++p,(*p)++区别?
  • .NET DevOps 接入指南 | 1. GitLab 安装
  • .Net Memory Profiler的使用举例
  • .net反编译工具