富文本

动态库或iWarch的应用的BundleID必须要跟主应用程序的bundleid一致,比如你的应用的id是com.mycop.hello,那么内嵌的id必须是com.mycop.hello.xxx

注意:mutable-content这个键值为1,这意味着此条推送可以被 Service Extension 进行更改,也就是说要用Service Extension需要加上这个键值为1.

inplist App Transport Security Settings

前言:

建议你去极光推送下载最新的demo看一下,也许就不用再参考我写的了。

实现的时候遇到的问题:

1.使用cocopods管理的时候少了个jpush-extension-ios.a文件

2.UNNotificationServiceExtension 中的方法打断点,没反应。不知道到底走了没有,集成成功了没有。(到现在我还不知道怎么让它有反应)

3.实现了之后通知栏的图片不见了。

开始了看好咯:

集成 jpush (查看极光文档)

1 、之前用的cocopods导入的时候 缺少了jpush-extension-ios.a文件 我现在直接改用手动导入了

手动集成.png

2、下载极光的SDK ,把里面的lib文件拷贝到工程中

lib文件.png

3.开启推送

开启推送.png

全局配置

NSAppTransportSecurity

NSAllowsArbitraryLoads

5、target - build Phases 中不能存在jpush-extension-ios.a文件(UNNotificationServiceExtension iOS 10才有的特性)

target.png

到这里就集成成功了

UNNotificationServiceExtension 的配置

1.创建 UNNotificationServiceExtension 文件

service.png

Service Extension的Bundle Identifier不能和Main Target(也就是你自己的App Target)的Bundle Identifier相同,否则会报BundeID重复的错误。

Service Extension的Bundle Identifier需要在Main Target的命名空间下,比如说Main Target的BundleID为io.jpush.xxx,那么Service Extension的BundleID应该类似与io.jpush.xxx.yyy这样的格式。如果不这么做,你可能会遇到一个错误。

然后再target中导入如下库文件

service Phases.png

3.ServiceExtension 里面的.plist文件加入全局配置

NSAppTransportSecurity

NSAllowsArbitraryLoads

UNNotificationServiceExtension 的代码实现

1.在头文件中导入

#import "JPushNotificationExtensionService.h"

并代码实现显示数据

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

self.contentHandler = contentHandler;

self.bestAttemptContent = [request.content mutableCopy];

self.bestAttemptContent.title = [NSString stringWithFormat:@"%@", self.bestAttemptContent.title]; //标题

self.bestAttemptContent.subtitle = [NSString stringWithFormat:@"%@", self.bestAttemptContent.subtitle];//副标题

self.bestAttemptContent.body = [NSString stringWithFormat:@"%@", self.bestAttemptContent.body];

NSURLSession * session = [NSURLSession sharedSession];

//图片链接字符串

NSString * attachmentPath = self.bestAttemptContent.userInfo[@"image_annex"][0];

NSLog(@"attachmentPath 1, %@",attachmentPath);

//if exist

if (attachmentPath && [attachmentPath hasSuffix:@"png"]) {

//download

NSURLSessionTask * task = [session dataTaskWithURL:[NSURL URLWithString:attachmentPath] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

if (data) {

NSString * localPath = [NSString stringWithFormat:@"%@/myAttachment.png", NSTemporaryDirectory()];

if ([data writeToFile:localPath atomically:YES]) {

UNNotificationAttachment * attachment = [UNNotificationAttachment attachmentWithIdentifier:@"myAttachment" URL:[NSURL fileURLWithPath:localPath] options:nil error:nil];

self.bestAttemptContent.attachments = @[attachment];

}

}

[self apnsDeliverWith:request];

}];

[task resume];

}else{

[self apnsDeliverWith:request];

}

}

- (void)apnsDeliverWith:(UNNotificationRequest *)request {

//please invoke this func on release version

//[JPushNotificationExtensionService setLogOff];

//service extension sdk

//upload to calculate delivery rate

//please set the same AppKey as your JPush

NSLog(@"attachmentPath 3");

[JPushNotificationExtensionService jpushSetAppkey:@"AppKey copied from JiGuang Portal application"];

[JPushNotificationExtensionService jpushReceiveNotificationRequest:request with:^ {

NSLog(@"apns upload success");

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);

}

到这里基本上已经差不多可以了,直接运行(网上很多说需要选择target,他们是做别的推送测试,极光在这里其实不用的),如果还显示还是有问题,跟服务端老哥对接下,查看一波 推送的payload 的aps 里面的格式。

对照一下下面的格式

{

aps = {

alert = {

'title' => "xxxxx",

'subtitle' => "xxx",

'body' => "none-body",

};

badge = 10;

"mutable-content" = 1;

sound = sound;

};

"image_annex" = (

"http://p1b05siky.bkt.clouddn.com/o_1c46hne9017pn1a1g1vth86hnnra.png"

);

}

//alert 必须有

//"mutable-content" = 1;这个必须有,使你的推送通知是动态可变的

//而且alert 字段与 mutable-content字段必须平级。

附:之前跟后台老哥交流时他把"mutable-content" = 1;放进alert中 导致图片一致出不来,还好我机智把userInfo打印出来看到的问题点,不然就炸了 ,照都找不到问题。

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {

// Required

NSDictionary * userInfo = notification.request.content.userInfo;

//打印userInfo

service Extension 断点调试问题

还没搞懂!!!!! 网上的说法是切换serviceExtension 选择目标APP运行,但还是不行 。

有大佬看见请Carry 我,thx。

java极光推送ios设置通知标题,iOS_极光推送的UNNotificationServiceExtension实现富文本...相关推荐

  1. java极光推送ios设置通知标题,iOS 极光推送接受通知和自定义消息及静默推送

    由于配置证书和注册极光应用配置网上已经很多了所以在这里就不在多说了!!! 1.首先我们要先将从极光官网上下载来的最新的sdk中的lib文件夹导入工程中; 顺便添加一些依赖库如下: /**添加依赖库 C ...

  2. 浅谈iOS和Android后台实时消息推送的原理和区别

    http://www.52im.net/thread-286-1-1.html 前言 iOS和Android上的实时消息推送差异很大,往小了说是技术实现的差异,往大了说是系统实现理念的不同.实时消息推 ...

  3. 苹果cms百度php推送示例,苹果cms百度主动URL推送教程

    为了提高网站seo优化,网站搭建正常运转后我们需要对网站的视频,资讯,文章等内容数据能够及时的提交给百度搜索,缩短蜘蛛爬取收录时间加快收录.我们需要对苹果cms系统自带的百度主动URL推送进行设置使用 ...

  4. Java web/springboot上传word/doc/docx文档(含图片)与HTML富文本导入/导出互相转换解析!附项目源码

    测试效果 先看下效果 文档内容如下: 上传 上传docx文档 查看解析内容 <html><head><style>p{margin-top:0pt;margin-b ...

  5. iOS开发之 - 好玩的富文本

    周末闲着没事,就想着不如把那些容易遗忘的知识点整理一下,一来可以让有需要的朋友少走弯路,二来自己以后再忘记的时候也可以回头看看......但 iOS 中小冷易忘的知识点实在太多了,不知道该从哪里开始整 ...

  6. iOS小技能:富文本图文混排

    文章目录 引言 I.基础知识&工具 1.1 封装富文本API,采用block实现链式编程 1.2 属性 II.超链接属性的应用案例 III.HTML字符串与富文本互转 IV.创建带有图片的富文 ...

  7. JAVA 极光推送后台实现触发,推送自定义消息、通知、定时推送、批量推送

    极光推送在众多的消息推送里,口碑算是很好的,项目中我负责的是这一块,就整理了这篇博客帮助记忆: 极光推送官方SDK文档:https://docs.jiguang.cn/jpush/server/sdk ...

  8. Android,ios,安卓app推送消息通知,java后台向手机推送app的通知教程

    文章目录 一.业务介绍 1.1 产品简介 1.2 名词解释 1.3 消息推送流程 二.应用创建 三.客户端 SDK 集成 3.1 Android 3.2 iOS 四.服务端推送 4.1 服务端消息下发 ...

  9. Java推送IOS通知消息

    Java推送IOS通知消息 公司需要做IOS消息推送,我负责后台代码的实现.写这篇文章也是将我踩坑得来的结果记录一下,分享一下. APN介绍 Apple 推送通知服务(APNs) 是远程通知功能的核心 ...

最新文章

  1. vant 1.6.6 发布,轻量级移动端 Vue 组件库
  2. 【翻译】在Sencha应用程序中使用插件和混入
  3. AES算法相关数学知识 - 素域学习
  4. 关于SharePoint 2010体系架构的几个话题
  5. 使用Angular可重用Component思路实现一个自带图标(icon)的input控件
  6. tcpdump启动脚本
  7. 深入理解Web Service
  8. springboot项目中使用spring的xml文件
  9. Dialogue System for Unity文档中英对照版(简雨原创翻译)第六篇(音序器相关,语音同步)
  10. SnapGene 4.3.6 for win —— 医学生的救星
  11. Debug Blocker
  12. 【干货】淘金币用户体验升级(含直播回放)
  13. Linux中合并多个Pdf文件(使用pdfunite,合并比较简单)
  14. Selenium的显示等待和隐式等待
  15. 基于opencv的BackgroundSubtractorMOG2和BackgroundSubtractorKNN通过背景减除来实现目标追踪
  16. linux双显卡配置_Linux系统怎么配置双显卡
  17. Python老司机带你快速搞定日志分析工具
  18. 《我是一只IT小小鸟》连载五
  19. 计算机博士情商低,为何实验室内部分博士生情商不高,不太懂人情世故?
  20. 爬虫爬取糗事百科段子

热门文章

  1. python判断网页密码加密方式_Python模拟网页中javascript加密与验证的相关处理
  2. android蓝牙串口arduino源码,android – Arduino:使用串口和软件串口与蓝牙模块
  3. Python数据结构:汉诺塔问题
  4. 千万级别数据查询优化_从千万级数据查询来聊一聊索引结构和数据库原理
  5. 二级C语言程序设计备考方法
  6. Flink java wordcount案例(批处理、流处理)
  7. docker安装ping命令
  8. mysql 数据库导出全部数据到excel,并保存为不同的sheet
  9. 布林通道参数用20还是26_这样设置均线参数
  10. Java可以用到军事方面吗_恭喜遥三运载火箭发射成功,浅谈java在军事方面的运用!...