iOS13 的适配

1.限制使用 KVC 修改私有属性

iOS13以后已经不能肆无忌惮的通过 KVC来修改一些没有暴露出来的属性了,否则会崩溃,例如以下代码

[_textField setValue:[UIColor xxx] forKeyPath:@"_placeholderLabel.textColor"]; 

[searchBar valueForKey:@"_searcField"];

可以通过 TextField 的 attributeString 设置

2.模态弹出默认交互改变

之前的默认交互是UIModalPresentationFullScreen,iOS13 后是UIModalPresentationAutomatic.设置一下即可

 myVC.modalPresentationStyle = UIModalPresentationFullScreen;

3.蓝牙权限说明

Privacy - Bluetooth Always Usage Description

替代了

Privacy - Bluetooth Peripheral Usage Description

info.plist 必须要添加Privacy - Bluetooth Always Usage Description,否则会崩溃;

4.兼容iOS13的黑色主题色

升级 iOS13 以后,默认UIUserInterfaceStyle为 Dark,导致很多界面显示风格不一致,

    4.1,识别当前的配色方案,可以通过viewcontroller.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark来获取,需要添加if (@available(iOS 12.0, *))以支持iOS12以下的系统。

    4.2,全局关闭黑暗模式,如果前期没有足够时间去适配暗黑模式,可以通过全局关闭黑暗模式避免暗黑模式下显示问题,只需要在 info.plist 文件里将UIUserInterfaceStyle key 的值设置为 Light即可

5. LaunchImage将废弃,使用LaunchScreen

使用LaunchImage的话,要求我们必须提供各种屏幕尺寸的启动图,来适配各种设备,随着苹果设备尺寸越来越多,这种方式显然不够 Flexible。而使用 LaunchScreen的话,情况会变的很简单, LaunchScreen是支持AutoLayout+SizeClass的,所以适配各种屏幕都不在话下。

从2020年4月开始,所有使⽤ iOS13 SDK的 App将必须提供 LaunchScreen,LaunchImage即将退出历史舞台。

6.tabbar 红点偏移

如果之前有通过TabBar上图片位置来设置红点位置,在iOS13上会发现显示位置都在最左边去了。遍历UITabBarButton的subViews发现只有在TabBar选中状态下才能取到UITabBarSwappableImageView,解决办法是修改为通过UITabBarButton的位置来设置红点的frame

 Push后Pop回来tabbar选中文字颜色变系统蓝色

self.tabBar.tinColor = color;

或者

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

self.tabBar.unselectedItemTintColor = color;

}

7. UITabBar上分割线呢操作

[[UITabBar appearance] setBackgroundImage:[UIImage new]];

[[UITabBar appearance] setShadowImage:[UIImage new]];

原来设置分割线的方式失效了,最新更改TabBar上细线方式实例,利用苹果提供的新API,为所欲为(改图片,改颜色)

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

#ifdef __IPHONE_13_0

UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];

appearance.backgroundImage = [UIImage new];

appearance.shadowImage = [UIImage imageNamed:@"Dotted_Line"];

appearance.shadowColor = [UIColor clearColor];

self.tabBar.standardAppearance = appearance;

#endif

} else {

self.tabBar.backgroundImage = [UIImage new];

self.tabBar.shadowImage = [UIImage imageNamed:@"Dotted_Line"];

}

8.可排序tableview的右侧三条杠会随着主题色改变色彩,并不会检测你自己设置的屏幕底色。两种方法,

    3.1.根据上面的方法来识别主题色从而给不同的底色来适配。

    3.2.强行更改三条杠为其他图片。

for (UIView * view in self.subviews)

    {

        if ([NSStringFromClass([view class]) rangeOfString:@"Reorder"].location != NSNotFound)

        {

            for (UIView * subview in view.subviews)

            {

                if ([subview isKindOfClass: [UIImageView class]])

                {

                    ((UIImageView *)subview).image = .....;

                }

            }

        }

   }


9.黑线处理crash

之前为了处理搜索框的黑线问题会遍历后删除UISearchBarBackground,在iOS13会导致UI渲染失败crash;解决办法是设置UISearchBarBackground的layer.contents为nil

public func clearBlackLine()

{

for view in self.subviews.last!.subviews

{

if view.isKind(of:NSClassFromString("UISearchBarBackground")!)

{

view.backgroundColor=UIColor.white

view.layer.contents=nilbreak

}

}

10.UIWebView弃用

苹果已经从iOS13禁止UIWebView方式了,需要更换WKWebView(过渡期仍可用,只是邮件警告,目前不影响审核)

11.WKWebView 中测量页面内容高度的方式变更

iOS 13以前 document.body.scrollHeight iOS 13开始 document.documentElement.scrollHeight

12.CNCopyCurrentNetworkInfo变化

iOS13下不能正常获取到WiFi的ssid,需要用户开启定位权限或者使用新的API NEHotspotConfiguration获取

13.在其他queue里不能直接创建viewcontroller,alloc都不行,否则会被阻塞。

以往我都是先创建好controller,在present的时候再跑到dispatch_async(dispatch_get_main_queue()里,但iOS13不行,创建controller时就需要在main queue里。

14.Xcode10往iOS13上编译运行提示 Could not find Developer Disk Image

下载开发包

强制退出Xcode(必须退出干净)

前往"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport"粘贴解压缩文件(以自己实际路径实际名称)

15.第三方登录

苹果更新的审核规范中提到使用第三方登录的APP必须要将apple登录作为一个可选择项,且必须放首位.

16.MPMoviePlayerController 在iOS 13已经不能用了

替代方案就是AVKit里面的那套播放器。

17.App启动过程中部分View可能无法实时获取到frame

可能是为了优化启动速度,App 启动过程中,部分View可能无法实时获取到正确的frame

你可能感兴趣的:(iOS13 的适配)