
Xcode11
【W(wǎng)WDC2019 Session】Xcode 11新特性
Xcode官方文檔
iOS13的特性
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>
-
適配暗黑模式:
使用 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


