iOS13的一些變化 2021-07-29

1.KVC訪問(wèn)私有屬性的崩潰問(wèn)題

在Xcode11上使用- (void)setValue:(nullable id)value forKeyPath:(NSString *)keyPath方法訪問(wèn)私有屬性,編譯時(shí)會(huì)崩潰,例如:

[textField setValue:[UIColorredColor]forKeyPath:@"_placeholderLabel.textColor"];///崩潰[textField setValue:[UIFontsystemFontOfSize:14]forKeyPath:@"_placeholderLabel.font"];///崩潰

不過(guò)使用- (void)setValue:(nullable id)value forKey:(NSString *)key方法正常,例如:

[self setValue:baseTabBar forKey:@"tabBar"];//正常

2.即將廢棄的LaunchImage

隨著蘋果設(shè)備的型號(hào)日益增多,利用LaunchImage來(lái)設(shè)置啟動(dòng)圖顯然顯得不夠明智。

替代方式:使用LaunchScreen來(lái)設(shè)置啟動(dòng)圖。LaunchScreen是iOS8引入的,支持AutoLayout+SizeClass,所以用起來(lái)十分方便。據(jù)消息,明年4月份后,所有app必須提供LaunchScreen了,盡早替換吧。

3.完全廢棄的UIWebView

隨著iOS13的到來(lái),UIWebView的使用范圍定格在了iOS12。很早時(shí)間之前UIWebView就因存在內(nèi)存泄漏問(wèn)題被蘋果建議用WKWebView來(lái)替代。此次更是完全被廢棄?,F(xiàn)在上傳AppStore的應(yīng)用如果存在UIWebView,蘋果會(huì)給你發(fā)郵件告訴你,UIWebView的API已經(jīng)廢棄了。So,趕緊替換。

4.presentViewController的問(wèn)題

iOS 13 的 presentViewController 默認(rèn)有視差效果,模態(tài)出來(lái)的界面現(xiàn)在默認(rèn)都下滑返回。 一些頁(yè)面必須要點(diǎn)確認(rèn)才能消失的,需要適配。如果項(xiàng)目中頁(yè)面高度全部是屏幕尺寸,那么多出來(lái)的導(dǎo)航高度會(huì)出現(xiàn)問(wèn)題。所以手動(dòng)設(shè)置一下Style吧

self.modalPresentationStyle=UIModalPresentationFullScreen;

5.暗黑模式的適配

隨著iOS13的到來(lái),有了暗黑模式,需要我們開(kāi)發(fā)者花更多精力去適配,尤其是那些重量級(jí)項(xiàng)目,很費(fèi)時(shí)間。這里先不談適配問(wèn)題,以后再談。如果不適配的話需要你全局關(guān)閉暗黑模式。

方法:配置plist文件: 在Info.plist 文件中,添加UIUserInterfaceStyle key 名字為 User Interface Style 值為String,將UIUserInterfaceStyle key 的值設(shè)置為 Light。

6.增加藍(lán)牙權(quán)限申請(qǐng)

iOS13以前,使用藍(lán)牙時(shí)可以直接用,不會(huì)出現(xiàn)權(quán)限提示,iOS13后,再使用就會(huì)提示了。 在info.plist里增加

<key>NSBluetoothAlwaysUsageDescription</key><string>我們需要使用您的藍(lán)牙</string>`

7.DeviceToken 獲取

DeviceToken 獲取到的格式發(fā)生變化

#include<arpa/inet.h>-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{if(![deviceToken isKindOfClass:[NSData class]])return;constunsigned*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/…

8.MPMoviePlayerController 徹底棄用

MPMoviePlayerController 在 iOS 9 開(kāi)始被棄用,如果在 iOS 13 中繼續(xù)使用的話會(huì)直接拋出異常:

***Terminating app due to uncaught exception'NSInvalidArgumentException',reason:'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.'

9.UISearchDisplayController徹底棄用

在 iOS 8 之前,我們?cè)?UITableView 上添加搜索框需要使用 UISearchBar + UISearchDisplayController 的組合方式。

在 iOS 8 之后,蘋果就已經(jīng)推出了 UISearchController 來(lái)代替這個(gè)組合方式。在 iOS 13 中,如果還繼續(xù)使用 UISearchDisplayController會(huì)直接導(dǎo)致崩潰,崩潰信息如下

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.'

解決方法:使用UISearchController代替

10.[UIApplication sharedApplication].keyWindow API將被棄用

@property(nullable,nonatomic,readonly)UIWindow*keyWindowAPI_DEPRECATED("Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes",ios(2.0,13.0));

修改使用下方代碼獲取

[[[UIApplication sharedApplication]windows]objectAtIndex:0]

?著作權(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)容

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