iOS 13 適配(持續(xù)更新)

iOS 13 馬上就要來了,各位 iOS 開發(fā)的小伙伴們,iOS 13 beta版的適配工作可以做起來了,O(∩_∩)O哈哈~,不多廢話,直入主題!

Xcode 11 beta 版下載地址:https://developer.apple.com/download/

iOS 13 手機(jī)系統(tǒng)下載方式,可以用描述文件下載,但是該方法無法降級,建議用愛思助手,可以方便系統(tǒng)升降級;

1.CNCopyCurrentNetworkInfo 方法,獲取不到當(dāng)前連接的WiFi信息

如果想要獲取當(dāng)前手機(jī)連接的WiFi,肯定需要調(diào)用該方法,iOS 13之前用該方法獲取沒問題,iOS 13再用該方法就獲取不到了;那是什么原因呢?是有新方法嘛?還是說這事iOS 13beta版的bug;顯然不是:查閱官網(wǎng)才發(fā)現(xiàn):獲取不到WiFi是因?yàn)椋枰@取當(dāng)前定位信息(之前以為只有Android需要這么做,現(xiàn)在iOS也加了這個(gè)條件);官網(wǎng)地址:https://forums.developer.apple.com/thread/117371


可以看出在這三個(gè)條件下,CNCopyCurrentNetworkInfo這個(gè)方法才可以獲取到當(dāng)前連接WiFi信息;

參考代碼:


2.KVC 限制

[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];

調(diào)用該方法會(huì)導(dǎo)致xcode崩潰,iOS 13上可以正常運(yùn)行,但是用xcode跑會(huì)crash,報(bào)錯(cuò)信息:

'Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug'

修改方案:

textField.attributedPlaceholder = [[NSAttributedStringalloc] initWithString:@""attributes:@{NSForegroundColorAttributeName:[UIColor red]}];


3.UISegmentedControl 顏色設(shè)置方式改變

iOS 13之前設(shè)置 tintColor 的方式,已經(jīng)沒法改變UISegmentedControl的背景色,可通過以下方法改變:

_segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"one", @"two"]];

[_segmentedControl setBackgroundImage:[vUtilityAPP imageWithColor:[UIColor blueColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[_segmentedControl setBackgroundImage:[vUtilityAPP imageWithColor:[UIColor redColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];


4.iOS 13中 presentViewController 模態(tài)動(dòng)畫,跳轉(zhuǎn)問題修復(fù)

iOS 13之前 presentViewController 跳轉(zhuǎn)的 modalPresentationStyle 默認(rèn)為 UIModalPresentationFullScreen ;

在iOS 13中默認(rèn) style 被改為 UIModalPresentationAutomatic,可參考蘋果代碼注釋:

修改方案:

CLBaseWebViewController *webViewController = [[CLBaseWebViewController alloc] initWithURL:url type:type data:data];

UINavigationController *nav = [[UINavigationControlleralloc] initWithRootViewController:webViewController];

nav.modalPresentationStyle = UIModalPresentationFullScreen;

[self.navigationController presentViewController:nav animated:YES completion:nil];

即:將 vc.modalPresentationStyle 的值改為 UIModalPresentationFullScreen ;

5.[deviceToken description] 獲取到的格式發(fā)生變化

iOS 13正確獲取Devicetoken代碼:

#include <arpa/inet.h>

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

? ? if (![deviceToken isKindOfClass:[NSData class]]) return;

? ? const unsigned *tokenBytes = (const unsigned *)[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);

}

6.App啟動(dòng)過程中,部分View可能無法實(shí)時(shí)獲取到frame

// 只有等執(zhí)行完 UIViewController 的 viewDidAppear 方法以后,才能獲取到正確的值,在viewDidLoad等地方 frame Size 為 0,例如:

[[UIApplication sharedApplication] statusBarFrame];

7.適配暗黑模式(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

在iOS 13設(shè)備上,蘋果要求適配深夜模式,適配該模式的時(shí)候,本來想自己寫一個(gè)較詳細(xì)的,但是已經(jīng)看到一個(gè)小伙伴寫的很不錯(cuò)了,就直接拿過來啦,哈哈

參考地址:https://juejin.im/post/5cf6276be51d455a68490b26

如果還沒適配,需要先關(guān)閉暗黑模式:

全局關(guān)閉暗黑模式:

1.在Info.plist 文件中,添加UIUserInterfaceStyle?key 名字為?User Interface Style值為String;

2.將UIUserInterfaceStyle?key 的值設(shè)置為?Light;

8.UISearchBar

UISearchBar主要還是KVC獲取系統(tǒng)私有屬性,導(dǎo)致的坑,自己這邊項(xiàng)目中沒用到,但是有很多小伙伴遇到了,就一起記錄下:

參考地址 :http://yoferzhang.com/post/20190604Searchbarios13/

9.iOS 13 系統(tǒng)后臺(tái)停留時(shí)間為30秒!

最近做項(xiàng)目發(fā)現(xiàn),iOS 13系統(tǒng),在后臺(tái)超過30秒后,定時(shí)器會(huì)自動(dòng)停止,而在iOS 12系統(tǒng)就不會(huì)30秒就停止,需要在后臺(tái)做操作的小伙伴們,需要注意一下,對項(xiàng)目是否有影響!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容