《iOS13的特性和適配》

Xcode11

【W(wǎng)WDC2019 Session】Xcode 11新特性
Xcode官方文檔

iOS13的特性

眾多新功能,隨iOS13而來(lái)。

iOS13的適配

1. SceneDelegate

  • In iOS 13 and later, use UISceneDelegate objects to respond to life-cycle events in a scene-based app.
  • In iOS 12 and earlier, use the UIApplicationDelegate object to respond to life-cycle events.

Q: 基于Xcode11新建的工程,在iOS13以前的版本不展示window,如何解決?
A:在AppDelegate.h 中添加window:

@property (strong, nonatomic) UIWindow *window;
  • 如果不使用場(chǎng)景功能,在info.plist文鍵中刪除Application Scene Manifast。
  • 注釋掉AppDelegate中 UISceneSession lifecycle
//- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
//    // Called when a new scene session is being created.
//    // Use this method to select a configuration to create the new scene with.
//    return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
//}
//
//
//- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
//    // Called when the user discards a scene session.
//    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
//    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
//}

2. 不允許使用 valueForKey、setValue: forKey 獲取和設(shè)置私有屬性;

// crash代碼 
[tf setValue:[UIColor greenColor] forKeyPath:@"_placeholderLabel.textColor"];
[tf setValue:[UIFont systemFontOfSize:12.f] forKeyPath:@"_placeholderLabel.font"];

// 修復(fù)代碼
tf.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:tf.placeholder attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.f],NSForegroundColorAttributeName:[UIColor redColor]}];

(注意: 使用富文本修改placeholder時(shí), tf.placeholder不能為空.)

// crash代碼
UIButton *cancelBtn = [searchBar valueForKey:@"_cancelButton"];

// 修復(fù)代碼 (不建議)
UIButton *cancelBtn = [searchBar valueForKey:@"cancelButton"];

// 獲取狀態(tài)欄視圖 crash
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

3. 控制器的 modalPresentationStyle 新增UIModalPresentationAutomatic, 且在iOS13上被設(shè)置為默認(rèn)值;

iOS13效果:


1). 如果使用此效果模式, 需要適配頁(yè)面布局, 否則底部?jī)?nèi)容會(huì)被遮擋;
2). 如果不使用, 修改控制器的 modalPresentationStyle為其他值.
(注意: 系統(tǒng)類如發(fā)送短信修改style無(wú)效.)


4. 之前標(biāo)記為 API_DEPRECATED 部分類被移除

  • MPMoviePlayerController ==> AVPlayerViewController

  • UISearchDisplayController ==> UISearchController

  • UIAlertView

5. Sign in with Apple

  • 使用 Sign in with Apple 會(huì)更加方便、快捷、安全,蘋果不會(huì)追蹤用戶在應(yīng)用中的行為。所以,對(duì)于用戶來(lái)說(shuō)使用 Sign in with Apple 會(huì)更加安全。
  • App 沒(méi)有提供第三方登錄,不需要集成。如果用到了第三方登錄,那么需要提供 Sign in with Apple,而且必須放在最前面。
    集成 Sign in with Apple 功能.

6. 即將廢棄的 LaunchImage

iOS 8 之前我們是在 LaunchImage 來(lái)設(shè)置啟動(dòng)圖,但是隨著蘋果設(shè)備尺寸越來(lái)越多,我們需要在對(duì)應(yīng)的 aseets 里面放入所有尺寸的啟動(dòng)圖,這是非常繁瑣的一個(gè)步驟。因此在 iOS 8 蘋果引入了 LaunchScreen.storyboard,支持界面布局用的 AutoLayout + SizeClass ,可以很方便適配各種屏幕。

需要注意的是,蘋果在 Modernizing Your UI for iOS 13 section 中提到
,從2020年4月開始,所有支持 iOS 13 的 App 必須提供 LaunchScreen.storyboard,否則將無(wú)法提交到 App Store 進(jìn)行審批。


7. DeviceToken 獲取

// 以前的
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
    /// Required - 注冊(cè) DeviceToken
    [JPUSHService registerDeviceToken:deviceToken];
}
// iOS13
- (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  const unsigned int *tokenBytes = [deviceToken bytes];
  NSString *tokenString = [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])];
  rootViewController.deviceTokenValueLabel.text = tokenString;
  rootViewController.deviceTokenValueLabel.textColor =
      [UIColor colorWithRed:0.0 / 255
                      green:122.0 / 255
                       blue:255.0 / 255
                      alpha:1];
  NSLog(@"Device Token: %@", tokenString);
  [JPUSHService registerDeviceToken:deviceToken];
}

https://developer.umeng.com/docs/66632/detail/126489


8. UISegmentedControl 默認(rèn)樣式改變

iOS13以前:


iOS13:



9. 藍(lán)牙需要新增權(quán)限描述

iOS13 以后廢棄 NSBluetoothPeripheralUsageDescription,
iOS13新增 NSBluetoothAlwaysUsageDescription;


10. 廢棄UIWebview APIs

從 iOS13 開始蘋果將 UIWebview 列為過(guò)期API。 目前提交蘋果應(yīng)用市場(chǎng)(App Store)會(huì)反饋以下郵件提示:

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


11. CNCopyCurrentNetworkInfo 變化

 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.

iOS13 以后只有開啟了 Access WiFi Information capability,才能獲取到 SSID 和 BSSID


12. Dark Mode

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

  • 不適配暗黑模式情況下處理方式:
方法一: 修改代碼
if (@available(iOS 13.0, *)) {
    [UIApplication sharedApplication].keyWindow.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
} 

方法二: 修改info.plist
<key>UIUserInterfaceStyle</key>
<string>Light</string>

UIUserInterfaceStyle

  • 適配暗黑模式:

使用 QMUITheme 實(shí)現(xiàn)換膚并適配 iOS 13 Dark Mode


千里之行,始于足下。

參考文檔:
【W(wǎng)WDC2019 Session】Xcode 11新特性
Xcode官方文檔
眾多新功能,隨iOS13而來(lái)。
集成 Sign in with Apple 功能.
適配 iOS13(持續(xù)更新)
使用 QMUITheme 實(shí)現(xiàn)換膚并適配 iOS 13 Dark Mode

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 因?yàn)橐Y(jié)局swift3.0中引用snapKit的問(wèn)題,看到一篇介紹Xcode8,swift3變化的文章,覺(jué)得很詳細(xì)...
    uniapp閱讀 4,877評(píng)論 0 12
  • 推薦文章 iOS Swift 自定義導(dǎo)航欄 FLNavigationBar 解決所有問(wèn)題 WWDC 2019 Xc...
    松花蛋蘸醋閱讀 3,043評(píng)論 1 9
  • 我啊,真的挺幸福的。 今天我哥給我買了一千多塊錢的衣服,說(shuō)不感動(dòng)是假的,我真的很幸福。 我哥是...
    陌漠小姐閱讀 70評(píng)論 0 1
  • 昨天本是日更的第七天,我沒(méi)有更文字,復(fù)活卡被用掉了。日更這件事情因?yàn)椴皇巧畹谋匦杵?,所以一點(diǎn)小情緒小事情,它就被...
    巫格婭爾閱讀 153評(píng)論 0 1
  • 一天都沒(méi)時(shí)間運(yùn)動(dòng),晚上下班回家步行。到家放下手上帶的東西,立馬又去軍校廣場(chǎng)給孩子買東西,這樣算是運(yùn)動(dòng)吧!
    冰雪嫣然閱讀 124評(píng)論 0 0

友情鏈接更多精彩內(nèi)容