美文网首页
自己适配iOS13解决的问题总结

自己适配iOS13解决的问题总结

作者: 猿王 | 来源:发表于2020-05-14 14:35 被阅读0次

自己适配iOS13解决的问题总结

1.暗黑模式Dark Mode

iOS 13 推出暗黑模式,UIView默认背景色会变成暗黑色。适配暗黑模式的工作量较大,没有适配暗黑模式之前,先禁用。

处理方案:在plist文件中增加配置项UIUserInterfaceStyle,值为Light。

2. 模态视图弹出方式改变

在 iOS 13 UIModalPresentationStyle 枚举的定义中,苹果新加了一个枚举值:

typedefNS_ENUM(NSInteger,UIModalPresentationStyle){
...UIModalPresentationAutomaticAPI_AVAILABLE(ios(13.0))=-2,}

新的交互方式默认为下拉dismiss,且导航栏会留白空出;

如果需要点击取消按钮才消失界面的,需要适配;

如果你完全接受苹果的这个默认效果,那就不需要去修改任何代码。

如果需要做成全屏显示的界面,需要手动设置弹出样式:

-(UIModalPresentationStyle)modalPresentationStyle
{
returnUIModalPresentationFullScreen;
}

如果,之前代码已经设置了modalPresentationStyle的值,那你也不会有这个影响。对于想要找回原来默认交互的同学,直接设置如下即可:

在presentViewController之前加入这个代码:
[self presentViewController:imagePicker animated:YES completion:nil];

//设置模态视图弹出方式
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;

如果是使用storyboard创建界面的,可以在storyboard里修改对应的设置。

3. 蓝牙权限字段更新导致崩溃以及提交审核失败

在 iOS 13 中,苹果将原来蓝牙申请权限用的 NSBluetoothPeripheralUsageDescription 字段,替换为 NSBluetoothAlwaysUsageDescription 字段。

如果在 iOS 13 中使用旧的权限字段获取蓝牙权限,会导致崩溃。

解决方案就是在 Info.plist 中把两个字段都加上。

NSBluetoothPeripheralUsageDescription 字段,

NSBluetoothAlwaysUsageDescription 字段。

4.私有方法 KVC 被禁用

iOS13后不再允许valueForKey、setValue:forKey: 等方法获取或设置私有属性,虽然编译可以通过,但是在运行时会直接崩溃或不起作用。

👇下面的方法都没有用了哦
// UITextField 的 _placeholderLabel
[textField setValue:[UIColorblackColor]forKeyPath:@"_placeholderLabel.textColor"];

// UISearchBar 的 _searchField
[searchBar valueForKey:@"_searchField"];

解决方案:

UITextField有一个attributedPlaceholder属性,占位符富文本,和UILabel等控件的富文本设置一样,可以设置文字颜色,尺寸等。

self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName: UIColorFromRGB(0x86b4e1 ,1.0)}];

5.searchBar设置textField问题

我们不用再用kvc获取UISearchBar的textField了,因为,iOS13中系统将searchTextField属性暴露出来了,不再是私有属性了,你可以直接调用。

UITextField*searchField=_searchBar.searchTextField;

注意:以上写法在iOS13以下手机运行会崩溃,所以,暂时要写成两种情况的写法,iOS13依然沿用之前的旧写法。

-(void) viewDidLayoutSubviews

{

    [super viewDidLayoutSubviews];

    //设置placeholder颜色

    UITextField *searchField = [UITextField new];

    if(@available(iOS 13.0, *)) {

        //UISearchBar的self.searchTextField属性是readonly,不能直接用

        searchField =  _searchBar.searchTextField;

        searchField.backgroundColor = [UIColor clearColor];

    } else {

        searchField = [_searchBar valueForKey:@"_searchField"];

    }

    //    [searchField setValue:UIColorFromRGB(0xAAB7D7 ,1.0) forKeyPath:@"_placeholderLabel.textColor"];

    // 替换的方案

    searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:searchField.placeholder attributes:@{NSForegroundColorAttributeName: UIColorFromRGB(0xAAB7D7 ,1.0)}];

    searchField.textColor=UIColorFromRGB(0x7C99D6, 1.0);

}

注意:上面的设置必须要在SearchBar显示完成后,或者Layout布局完成后设置,在ios13中才有效,我之前在viewDidLoad中的设置在ios13中都没有效果了。

可以在viewDidLayoutSubviews或者viewDidAppear中进行设置。

特别强调一点,ios13要设置SearchBar输入框的背景色,请使用

searchField.backgroundColor = [UIColor clearColor];

在ios13以下我之前设置的SearchBar的backgroundimage是可以遮住SearchBar输入框的背景色的,但是在ios13上就没有效果了,希望注意。

6.UITabBarItem的位置问题

以前设置UITabBarItem的时候,需要设置位置下移6位,在ios13中发现不需要进行下移了。

解决方案:

if (@available(iOS 13.0, *)) {

        item1.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);

        item2.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);

        item3.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);

    }

7.deviceToken 获取到的格式发生变化

原本可以直接将 NSData 类型的 deviceToken 转换成 NSString 字符串,然后替换掉多余的符号即可:

NSString *datastring = [[[[NSString stringWithFormat:@"%@",data]

            stringByReplacingOccurrencesOfString: @"<" withString: @""]

            stringByReplacingOccurrencesOfString: @">" withString: @""]

          stringByReplacingOccurrencesOfString: @" " withString: @""];

在 iOS 13 中,这种方法已经失效,NSData类型的 deviceToken 转换成的字符串变成了:

{length = 32, bytes = 0xd7f9fe34 69be14d1 fa51be22 329ac80d ... 5ad13017 b8ad0736 }

需要进行一次数据格式处理,获取方式如下:

NSString *datastring =[self HexStringWithData:data];

//data转为十六进制字符串

-(NSString *)HexStringWithData:(NSData *)data{

    Byte *bytes = (Byte *)[data bytes];

    NSString *hexStr=@"";

    for(int i=0;i<[data length];i++) {

        NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff];///16进制数

        if([newHexStr length]==1){

            hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];

        }

        else{

            hexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];

        }

    }

    hexStr = [hexStr uppercaseString];

    return hexStr;

}

8.UIWebView 将被禁止提交审核

在 iOS 13 推出后,苹果在 UIWebView 的说明上将其支持的系统范围定格在了 iOS 2 ~ iOS 12。目前,如果开发者将包含 UIWebView api 的应用更新上传到 App Store 审核后,其将会收到包含 ITMS-90809 信息的回复邮件,提示你在下一次提交时将应用中 UIWebView 的 api 移除。

解决方案:

用WKWebView替代 UIWebView,确保所有 UIWebView 的 api 都要移除,如果需要适配 iOS 7 的可以通过 openURL 的方式在 Safari 打开。

9.MPMoviePlayerController 被弃用

在 iOS 9 之前播放视频可以使用 MediaPlayer.framework 中的MPMoviePlayerController类来完成,它支持本地视频和网络视频播放。但是在 iOS 9 开始被弃用,如果在 iOS 13 中继续使用的话会直接抛出异常:

***Terminating app due to uncaught exception'NSInvalidArgumentException',
reason:'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.'

解决方案:使用 AVFoundation 里的 AVPlayer。

10.LaunchImage 被弃用

苹果在 Modernizing Your UI for iOS 13 section 中提到,从2020年4月开始,所有支持 iOS 13 的 App 必须提供LaunchScreen.storyboard,否则将无法提交到 App Store 进行审批。

解决方案:

使用 LaunchScreen.storyboard 设置启动页,弃用 LaunchImage。

文章参考了:

iOS之iOS13适配总结

iOS13适配更新总结

iOS开发 之 iOS13新特性 以及 iOS13适配

相关文章

  • 自己适配iOS13解决的问题总结

    自己适配iOS13解决的问题总结 1.暗黑模式Dark Mode iOS 13 推出暗黑模式,UIView默认背景...

  • iOS13适配

    参考: iOS13 适配踩坑 - 持续更新 iOS 13 适配要点总结 iOS 13 适配要点总结 1、prese...

  • iOS13适配更新总结

    前言: iOS13的API的变动和适配问题,我从新特性适配、API 适配、方法弃用、工程适配、SDK 适配、其他问...

  • iOS13 适配详细

    对iOS13 适配的总结,下面有些是自己遇到的,有些是收集的,希望能给大家一些思路 iOS13中presentVi...

  • iOS13 适配问题 看这一篇就够了

    技术参考: apple login IOS13适配-详细 iOS 13 适配(持续更新中) iOS13适配 掘金 ...

  • iOS 13适配

    技术参考: apple login IOS13适配-详细 iOS 13 适配(持续更新中) iOS13适配 掘金 ...

  • iOS 13 SceneDelegate适配(Xcode 11,

    文章目录 最低适配的系统改到iOS13以下后 解决方案一:删除SceneDelegate,还原到iOS13以前的版...

  • iOS11 & iPhoneX适配

    原文10分钟适配 iOS 11 & iPhone XiOS11 & iPhoneX适配总结 适配中的问题及解决办法...

  • 针对iOS13一些适配问题的处理整理,持续更新

    以下是iOS13一些适配问题的暂时解决方案,整理以下,希望能帮到大家。 UITextField 异常 在设置lef...

  • iOS13适配(更新中)

    对于iOS13适配汇总以及遇到的问题注意:以下适配内容,必须适配的会以"必须"标出 1. Dark Model(必...

网友评论

      本文标题:自己适配iOS13解决的问题总结

      本文链接:https://www.haomeiwen.com/subject/sodtohtx.html