適配 iOS13(持續更新)

最後更新時間:2019-11-5css

不久前,蘋果WWDC19開發者大會在美國加州聖何塞舉行。此次大會上,蘋果公佈了 iOS13 的更新內容,今天咱們來看看如何適配 iOS13.html

Sign in with Apple

蘋果更新了審覈規則之後要求全部使用第三方登陸的應用必須向用戶提供以蘋果帳號登陸的選項, 而且要放前邊。但蘋果一樣舉出了幾種特例的狀況:ios

  • 僅使用公司內部帳號登錄。css3

  • 教育或者企業應用,須要使用現有的教育和企業賬號登陸。git

  • 應用須要使用政府或者行業背景的共名身份系統或者 電子ID 進行登陸。github

  • 應用是特定的第三方客戶服務客戶端,須要使用郵箱,社交賬號,或者其餘的三方服務來獲取他們的內容。web

  • Sign in with Apple 設計規範bash

  • App Store Review Guidelines微信

黑夜模式

Apps on iOS 13 are expected to support dark mode Use system colors and materials Create your own dynamic colors and images Leverage flexible infrastructureapp

// 模式強制切換
if (darkMode) {
    if (@available(iOS 13.0, *)) {
        [UIApplication sharedApplication].keyWindow.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
    }
} else {
    if (@available(iOS 13.0, *)) {
        [UIApplication sharedApplication].keyWindow.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
}
複製代碼

已知問題:

  • YYLabel 若是使用了 textLayout屬性,切換模式的時候 沒法自動修改layout文本的顏色(已解決,後續會單獨出文章)
  • 內嵌WebView,須要手動修改css樣式(可使用css3中的@media來解決)
  • CGColor沒法根據模式切換 [參考]

KVC 限制

iOS13 之後已經不能肆無忌憚的經過 KVC 來修改一些沒有暴露出來的屬性了。

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Access to xxx's _xxx ivar is prohibited. This is an application bug'

已知:

// UITextField 的 _placeholderLabel
[textField setValue:[UIColor xxx] forKeyPath:@"_placeholderLabel.textColor"];

// UISearchBar 的 _searchField
[searchBar valueForKey:@"_searchField"];
複製代碼

模態彈出默認交互改變

/*
 Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
 If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but other system-provided view controllers may resolve UIModalPresentationAutomatic to other concrete presentation styles.
 Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
 */
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle API_AVAILABLE(ios(3.2));
複製代碼

iOS 13presentViewController 默認有視差效果,模態出來的界面如今默認都下滑返回。 一些頁面必需要點確認才能消失的,須要適配。若是項目中頁面高度所有是屏幕尺寸,那麼多出來的導航高度會出現問題。

// Swift
self.modalPresentationStyle = .fullScreen

// Objective-C
self.modalPresentationStyle = UIModalPresentationFullScreen;
複製代碼

UISegmentedControl 默認樣式改變

默認樣式變爲白底黑字,若是設置修改過顏色的話,頁面須要修改

UITabbar 層次發生改變,沒法經過設置 shadowImage去掉上面的線

能夠參考 騰訊 QMUIKit 裏面的實現

App啓動過程當中,部分View可能沒法實時獲取到frame

多是爲了優化啓動速度,App 啓動過程當中,部分View可能沒法實時獲取到正確的frame

// 只有等執行完 UIViewController 的 viewDidAppear 方法之後,才能獲取到正確的值,在viewDidLoad等地方 frame Size 爲 0,例如:
 [[UIApplication sharedApplication] statusBarFrame];
複製代碼

標記爲 API_DEPRECATED 部分類被移除

  • MPMoviePlayerController ==> AVPlayerViewController
  • UISearchDisplayController ==> UISearchController
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'UISearchDisplayController is no longer supported when linking against this version of iOS. Please migrate your application to UISearchController.'
複製代碼

DeviceToken 獲取

DeviceToken 獲取到的格式發生變化

#include <arpa/inet.h>
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    if (![deviceToken isKindOfClass:[NSData class]]) return;
    const unsigned *tokenBytes = [deviceToken bytes];
    NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                          ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                          ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                          ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
    NSLog(@"deviceToken:%@",hexToken);
}
複製代碼

參考:developer.umeng.com/docs/66632/…

CNCopyCurrentNetworkInfo 變化

iOS13 之後只有開啓了 Access WiFi Information capability,才能獲取到 SSID 和 BSSID

An app that fails to meet any of the above requirements receives the following return value:

- An app linked against iOS 12 or earlier receives a dictionary with pseudo-values. In this case, the SSID is Wi-Fi (or WLAN in the China region), and the BSSID is 00:00:00:00:00:00.
- An app linked against iOS 13 or later receives NULL.
複製代碼

參考:CNCopyCurrentNetworkInfo

即將廢棄的 LaunchImage

iOS 8 以前咱們是在 LaunchImage 來設置啓動圖,可是隨着蘋果設備尺寸愈來愈多,咱們須要在對應的 aseets 裏面放入全部尺寸的啓動圖,這是很是繁瑣的一個步驟。所以在 iOS 8 蘋果引入了 LaunchScreen.storyboard,支持界面佈局用的 AutoLayout + SizeClass ,能夠很方便適配各類屏幕。

須要注意的是,蘋果在 Modernizing Your UI for iOS 13 section 中提到 ,從2020年4月開始,全部支持 iOS 13 的 App 必須提供 LaunchScreen.storyboard,不然將沒法提交到 App Store 進行審批。

使用藍牙須要添加權限描述

iOS 13之前,使用藍牙時能夠直接用,不會出現權限提示,iOS13之後使用就會提示。而且須要在info.plist裏增長 NSBluetoothAlwaysUsageDescription

Your app's code references one or more APIs that access sensitive user data. The app's Info.plist file should contain a NSBluetoothAlwaysUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. Starting Spring 2019, all apps submitted to the App Store that access user data are required to include a purpose string. If you're using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. You can contact the developer of the library or SDK and request they release a version of their code that doesn't contain the APIs. Learn more (developer.apple.com/documentati…).

ps:若是你的應用裏面沒有用到藍牙,卻提示這個問題,能夠檢查下 個推SDK 是否更新到最新版本

廢棄UIWebview APIs

iOS 有 UIWebviewWKWebview 兩種Webview。從 iOS13 開始蘋果將 UIWebview 列爲過時API。 目前提交蘋果應用市場(App Store)會反饋如下郵件提示:

ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs .
See developer.apple.com/documentati… for more information.

查找哪些SDK包含了 UIWebView

find . -type f | grep -e ".a" -e ".framework" | xargs grep -s UIWebView

目前經常使用的SDK中,已知更新移除 UIWebView 的版本有:

  • QQ登陸 (v3.3.6)
  • ShareSDK (v4.3.2)
  • 極驗證 (v0.12.5)
  • 新浪微博(v3.2.5)
  • 微信開放平臺 (v1.8.6.1)

暫未更新移除 UIWebView 版本的 SDK :

  • 谷歌廣告

部分關於 UIWebView 審覈問題的討論:

dcloud Cocos2d-x ShareSDK

Non-Public API usage

蘋果更新了 Non-public API usage 掃描的庫, 致使不少知名第三方庫被誤傷:

  • fmdb
  • SSZipArchive
  • CocoaLumberjack

ITMS-90338: Non-public API usage - The app references non-public selectors in {APPName}: _clearBackgroundViews, databasePool:didAddDatabase:, databasePool:shouldAddDatabaseToPool:, ddSetLogLevel:, zipArchiveDidUnzipFileAtIndex:totalFiles:archivePath:unzippedFilePath:, zipArchiveProgressEvent:total:. If method names in your source code match the private Apple APIs listed above, altering your method names will help prevent this app from being flagged in future submissions. In addition, note that one or more of the above APIs may be located in a static library that was included with your app. If so, they must be removed. For further information, visit the Technical Support Information at developer.apple.com/support/tec…

模擬器問題

Xcode 11.1 若是碰到 模擬器啓動的時候卡住的話,能夠把 模擬器 -> Edit-> Automatically sync pastaBoard 關掉

MJExtension 問題

Stack overflow in +[NSObject(Property) mj_properties] 升級 MJExtension 至 3.1.0版本以上,棄用老方法,涉及到全部方法添加 mj_ 前綴。

相關文章
相關標籤/搜索