iOS原生推送(APNS)进阶iOS10推送图片、视频、音乐

本文介绍了如何在iOS10及以上版本使用APNS实现原生推送并展示图片和视频。文章详细讲解了创建UNNotificationServiceExtension、处理推送内容、适配ATS以及自定义推送UI的步骤,并提供了遇到的问题及解决方案,附带项目结构图和代码地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码地址如下:
http://www.demodashi.com/demo/13208.html

前言

我们首先要在AppDelegate里面进行iOS的适配,可以参考这篇文章

iOS原生推送(APNS)的实现
如果已经适配过了请忽略。

程序实现

Xcode打开项目,File–>New–>Target;

然后分别选UNNotificationServiceExtension、UNNotificationContent创建Target;

然后在UNNotificationServiceExtension的- (void)didReceiveNotificationRequest:(UNNotificationRequest )request withContentHandler:(void (^)(UNNotificationContent _Nonnull))contentHandler {}方法中添加下面的代码;

NSMutableArray *actionMutableArr = [[NSMutableArray alloc] initWithCapacity:1];

UNNotificationAction * actionA  =[UNNotificationAction actionWithIdentifier:@"ActionA" title:@"不感兴趣" options:UNNotificationActionOptionAuthenticationRequired];

UNNotificationAction * actionB = [UNNotificationAction actionWithIdentifier:@"ActionB" title:@"不感兴趣" options:UNNotificationActionOptionDestructive];

UNNotificationAction * actionC = [UNNotificationAction actionWithIdentifier:@"ActionC" title:@"进去瞅瞅" options:UNNotificationActionOptionForeground];

UNTextInputNotificationAction * actionD = [UNTextInputNotificationAction actionWithIdentifier:@"ActionD" title:@"作出评论" options:UNNotificationActionOptionDestructive textInputButtonTitle:@"send" textInputPlaceholder:@"say some thing"];

[actionMutableArr addObjectsFromArray:@[actionA,actionB,actionC,actionD]];

if (actionMutableArr.count) {

UNNotificationCategory * notficationCategory = [UNNotificationCategory categoryWithIdentifier:@"categoryNoOperationAction" actions:actionMutableArr intentIdentifiers:@[@"ActionA",@"ActionB",@"ActionC",@"ActionD"] options:UNNotificationCategoryOptionCustomDism
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值