ios 13 适配要点总结

iOS 13支持适配的机型

iPhone X、iPhone XR、iPhone XS、iPhone XS Max
iPhone 8、iPhone 8 Plus
iPhone 7、iPhone 7 Plus
iPhone 6s、iPhone 6s Plus
iPhone SE
iPod touch (第七代)

适配要求

Starting April, 2020, all iPhone and iPad apps submitted to the App Store will need to be built with the iOS 13 SDK or later. They must also support the all-screen design of iPhone XS Max or the 12.9-inch iPad Pro (3rd generation), or later.

根据官网的说法,2020年4月之后所有提交到 App Store 的 iPhone 和 iPad 应用必须使用 iOS 13 以上的 SDK 进行编译,并支持 iPhone Xs Max 或 12.9 寸 iPad Pro (3代) 及以后版本的全屏幕设计。

新特性适配

  1. Dark Mode

iOS 13 推出暗黑模式,UIKit 提供新的系统颜色和 api 来适配不同颜色模式,xcassets 对素材适配也做了调整,具体适配可见: https://developer.apple.com/videos/play/wwdc2019/214/

如果不打算适配 Dark Mode,可以直接在 Info.plist 中添加一栏:User Interface Style : Light,即可在应用内禁用暗黑模式。不过即使设置了颜色方案,申请权限的系统弹窗还是会依据系统的颜色进行显示,自己创建的 UIAlertController 就不会。

  1. Sign In with Apple

在 iOS 13 中苹果推出一种在 App 和网站上快速、便捷登录的方式: Sign In With Apple。这是 iOS 13 新增的功能,因此需要使用 Xcode 11 进行开发。关于应用是否要求接入此登录方式,苹果在 App Store 应用审核指南 中提到:

Apps that exclusively use a third-party or social login service (such as Facebook Login, Google Sign-In, Sign in with Twitter, Sign In with LinkedIn, Login with Amazon, or WeChat Login) to set up or authenticate the user’s primary account with the app must also offer Sign in with Apple as an equivalent option.

如果你的应用使用了第三方或社交账号登录服务(如Facebook、Google、Twitter、LinkedIn、Amazon、微信等)来设置或验证用户的主账号,就必须把 Sign In With Apple 作为同等的选项添加到应用上。如果是下面这些类型的应用则不需要添加:

仅仅使用公司内部账号来注册和登录的应用;
要求用户使用现有的教育或企业账号进行登录的教育、企业或商务类型的应用;
使用政府或业界支持的公民身份识别系统或电子标识对用户进行身份验证的应用;
特定第三方服务的应用,用户需要直接登录其邮箱、社交媒体或其他第三方帐户才能访问其内容。

另外需要注意,关于何时要求接入 Sign In With Apple,苹果在 News and Updates 中提到:

Starting today, new apps submitted to the App Store must follow these guidelines. Existing apps and app updates must follow them by April 2020.

2019 年 9 月 12 日 起,提交到 App Store 的新应用必须按照应用审核指南中的标准进行接入;现有应用和应用更新必须也在 2020 年 4 月前完成接入。

API 适配

  1. 私有方法 KVC 可能导致崩溃

在 iOS 13 中部分方法属性不允许使用 valueForKey、setValue:forKey: 来获取或者设置私有属性,具体表现为在运行时会直接崩溃,并提示以下崩溃信息:

*** Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘Access to UISearchBar’s _searchField ivar is prohibited. This is an application bug’

目前整理的会导致崩溃的私有 api 和对应替代方案如下,感谢 @君赏 的反馈,也欢迎各位大佬补充和指正

// 崩溃 api
UITextField *textField = [searchBar valueForKey:@”_searchField”];

// 替代方案 1,使用 iOS 13 的新属性 searchTextField
searchBar.searchTextField.placeholder = @”search”;

// 替代方案 2,遍历获取指定类型的属性

  • (UIView )findViewWithClassName:(NSString )className inView:(UIView *)view{
    Class specificView = NSClassFromString(className);
    if ([view isKindOfClass:specificView]) {

    return view;
    

    }

    if (view.subviews.count > 0) {

    for (UIView *subView in view.subviews) {
        UIView *targetView = [self findViewWithClassName:className inView:subView];
        if (targetView != nil) {
            return targetView;
        }
    }
    

    }

    return nil;
    }

// 调用方法
UITextField *textField = [self findViewWithClassName:@”UITextField” inView:_searchBar];