iOS 13 適配(持續更新)

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

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

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

1.CNCopyCurrentNetworkInfo 方法,獲取不到當前連接的WiFi信息

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


可以看出在這三個條件下,CNCopyCurrentNetworkInfo這個方法才可以獲取到當前連接WiFi信息;

參考代碼:


2.KVC 限制

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

調用該方法會導致xcode崩潰,iOS 13上可以正常運行,但是用xcode跑會crash,報錯信息:

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

修改方案:

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


3.UISegmentedControl 顏色設置方式改變

iOS 13之前設置 tintColor 的方式,已經沒法改變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 模態動畫,跳轉問題修復

iOS 13之前 presentViewController 跳轉的 modalPresentationStyle 默認為 UIModalPresentationFullScreen ;

在iOS 13中默認 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] 獲取到的格式發生變化

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啟動過程中,部分View可能無法實時獲取到frame

// 只有等執行完 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設備上,蘋果要求適配深夜模式,適配該模式的時候,本來想自己寫一個較詳細的,但是已經看到一個小伙伴寫的很不錯了,就直接拿過來啦,哈哈

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

如果還沒適配,需要先關閉暗黑模式:

全局關閉暗黑模式:

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

2.將UIUserInterfaceStyle?key 的值設置為?Light;

8.UISearchBar

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

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

9.iOS 13 系統后臺停留時間為30秒!

最近做項目發現,iOS 13系統,在后臺超過30秒后,定時器會自動停止,而在iOS 12系統就不會30秒就停止,需要在后臺做操作的小伙伴們,需要注意一下,對項目是否有影響!

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

推薦閱讀更多精彩內容