阅读 674

iOS15适配本地通知功能

引言

粉丝福利:搜索#小程序:iOS逆向 ,关注公众号:iOS逆向领取福利【掘金小册5折优惠码】

一年一度的iOS 系统 API适配来了,9 月 14 日起 App Store Connect 已经开放 iOS 15 和 iPadOS 15 App 的提交,同时苹果宣布自 2022 年 4 月起,所有提交至 App Store 的 iOS 和 iPadOS app 都必须使用 Xcode 13 和 iOS 15 SDK 构建。

Xcode 13 正式版包含 iOS 15,iPadOS 15,tvOS 15,watchOS 8 以及 macOS Big Sur 11.3 SDK。Xcode 13 需在 macOS 11.3 及以上版本运行,支持 iOS 9,tvOS 9,watchOS 2 及以上系统设备调试;

也正式支持了 Vim。

Xcode 13 Release Notes: developer.apple.com/documentati… 在这里插入图片描述

I 消息推送

推送新特性: iOS15以上的新增属性 interruptionLevel为枚UNNotificationInterruptionLevel

1.1 本地推送适配

需求:利用本地推送实现消息的语音播报 问题:iOS12.1之后利用本地推送实现消息的语音播报,在iOS15 没有声音。kunnan.blog.csdn.net/article/det…

原因: iOS15本地推送新增了中断级别属性 interruptionLevel,对通知进行了分级 。而且通知的内容不能为空。

方案:使用非Passive的中断级别进行本地通知才会有声音,且本地推送一定要有内容,即body不能为空。content.body = @" 不能为空";

在这里插入图片描述

        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];         UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];         content.title = @"";         content.subtitle = @"";         content.sound = [UNNotificationSound soundNamed:fileName];         content.badge = @(1);                  if (@available(iOS 15.0, *)) {             content.interruptionLevel = UNNotificationInterruptionLevelTimeSensitive;//会使手机亮屏且会播放声音;可能会在免打扰模式(焦点模式)下展示 // @"{\"aps\":{\"interruption-level\":\"time-sensitive\"}}"; // @"{\"aps\":{\"interruption-level\":\"active\"}}";             content.body = @" ";// 本地推送一定要有内容,即body不能为空。                      }else{                          content.body = @"";         }                  UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.001 repeats:NO];         // 添加通知的标识符,可以用于移除,更新等操作         NSString *identifier = [NSString stringWithFormat:@"localPushId%lld", (long long)[[NSDate date] timeIntervalSince1970]];         UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];         [center addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error) {             CGFloat waitTime = [self timeForAudioFileWithFileName:fileName]; //            CGFloat waitTime = 0.3;                          dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(waitTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{                 [self localNotificationPushNextFile];             });         }]; 复制代码

中断级别目前分为四种:

typedef NS_ENUM(NSUInteger, UNNotificationInterruptionLevel) {     // Added to the notification list; does not light up screen or play sound     UNNotificationInterruptionLevelPassive,          // Presented immediately; Lights up screen and may play a sound     UNNotificationInterruptionLevelActive,          // Presented immediately; Lights up screen and may play a sound; May be presented during Do Not Disturb     UNNotificationInterruptionLevelTimeSensitive,          // Presented immediately; Lights up screen and plays sound; Always presented during Do Not Disturb; Bypasses mute switch; Includes default critical alert sound if no sound provided     UNNotificationInterruptionLevelCritical, } API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)); 复制代码

  1. Passive:被动类型的通知不会使手机亮屏并且不会播放声音。

  2. Active: 活动类型的通知会使手机亮屏且会播放声音,为默认类型。

  3. Time Sensitive(时间敏感):会使手机亮屏且会播放声音;可能会在免打扰模式(焦点模式)下展示。

设置推送通知数据: 时间敏感的中断级别可以使用“interruption-level” payload key:{"aps":{"interruption-level":"time-sensitive"}}

时效性通知开发者无法直接使用,需要配置对应的权限: a. xcode 开启对应能力

在这里插入图片描述

b. 开发者后台配置appID支持该权限(通过Xcode开启对应能力通常会自动添加)

在这里插入图片描述

  1. Critical(关键):会立刻展示,亮屏,播放声音,无效免打扰模式,并且能够绕过静音,如果没有设置声音则会使用一种默认的声音。

适用于地震等紧急情况,需要特殊申请。

判断是否有时间敏感权限  @property(readonly, nonatomic) UNNotificationSetting timeSensitiveSetting;,如果没有需要提示用户开启。

UNNotificationSetting

typedef NS_ENUM(NSInteger, UNNotificationSetting) {     // The application does not support this notification type     UNNotificationSettingNotSupported  = 0,          // The notification setting is turned off.     UNNotificationSettingDisabled,          // The notification setting is turned on.     UNNotificationSettingEnabled, } API_AVAILABLE(macos(10.14), ios(10.0), watchos(3.0), tvos(10.0)); 复制代码

1.2 测试

开发者想打ad hot 的话,需要能访问云端管理的分发证书。 在这里插入图片描述

可以使用极光的网页端或者接口进行测试,或者使用smart push。

在这里插入图片描述

1.3 升级JPush iOS SDK

v4.4.0: pod 'JPush' , '4.4.0'

docs.jiguang.cn/changelog/j…

更新时间:2021-10-28

Change Log:

SDK适配ios15系统的本地通知功能

富媒体横屏异常兼容性处理

错误信息: ld: library not found for -ljcore-ios-2.3.4

原因:other linker flags 的信息没有自动更新

在这里插入图片描述

解决方案:直接删除other linker flags的jcore信息即可

see also

更多内容请关注#小程序:iOS逆向,只为你呈现有价值的信息,专注于移动端技术研究领域。


作者:公众号iOS逆向
链接:https://juejin.cn/post/7026217314081046564

文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐