iOS 13適配匯總(推薦)
隨著iPhone 11的發(fā)布,iOS 13適配也提上了日程,接下來(lái)就開(kāi)發(fā)中升級(jí)iOS13的手機(jī)可能出現(xiàn)的問(wèn)題
Xcode: 11.0
iOS : 13.0
UIViewController 模態(tài)彈出界面
viewController.present(presentVC, animated: true, completion: nil)
在調(diào)用模態(tài)彈出視圖,會(huì)發(fā)現(xiàn)彈出的界面沒(méi)有全屏。如圖

通過(guò)多次的嘗試,發(fā)現(xiàn)在低版本里面不會(huì)發(fā)生這種情況(iOS12及以下),于是我查閱了最新的開(kāi)發(fā)文檔,發(fā)現(xiàn)了端倪,主要還是因?yàn)槲覀冎昂雎粤?strong>UIViewController里面的一個(gè)屬性,即:modalPresentationStyle
Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but other system-provided view controllers may resolve UIModalPresentationAutomatic to other concrete presentation styles.
Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
public enum UIModalPresentationStyle : Int {
case fullScreen
@available(iOS 3.2, *)
case pageSheet
@available(iOS 3.2, *)
case formSheet
@available(iOS 3.2, *)
case currentContext
@available(iOS 7.0, *)
case custom
@available(iOS 8.0, *)
case overFullScreen
@available(iOS 8.0, *)
case overCurrentContext
@available(iOS 8.0, *)
case popover
@available(iOS 7.0, *)
case none
@available(iOS 13.0, *)
case automatic
}
通過(guò)查看API 可以看到,iOS 13 新增一個(gè):automatic類(lèi)型,默認(rèn)情況下就是這個(gè)所以才會(huì)彈出不是全屏的界面。如果我們想要修改為全屏的話(huà)
可以:presentVC.modalPresentationStyle = .fullScreen設(shè)置為全屏即可
KVC 限制
iOS13以后已經(jīng)不能肆無(wú)忌憚的通過(guò) KVC來(lái)修改一些沒(méi)有暴露出來(lái)的屬性了。
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Access to xxx's _xxx ivar is prohibited. This is an application bug'
我們常用的有
// UITextField 的 _placeholderLabel
let textField = UITextField.init()
textField.setValue(UIColor.red, forKey: "_placeholderLabel.textColor")
/// UISearchBar 的 _searchField
[searchBar valueForKey:@"_searchField"]
下面方法替換
///分別設(shè)置字體大小和顏色(富文本) textField.attributedPlaceholder = NSAttributedString.init(string: "請(qǐng)輸入....", attributes: [NSAttributedString.Key.foregroundColor: UIColor.red], [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15)]) /// UISearchBar 用 searchField代替 bar.value(forKey: "searchField") as! UITextField
UISegmentedControl 默認(rèn)樣式改變
默認(rèn)樣式變?yōu)榘椎缀谧?,如果設(shè)置修改過(guò)顏色的話(huà),頁(yè)面需要修改
UITabbar
如果之前有通過(guò)TabBar上圖片位置來(lái)設(shè)置紅點(diǎn)位置,在iOS13上會(huì)發(fā)現(xiàn)顯示位置都在最左邊去了。遍歷UITabBarButton的subViews發(fā)現(xiàn)只有在TabBar選中狀態(tài)下才能取到UITabBarSwappableImageView,解決辦法是修改為通過(guò)UITabBarButton的位置來(lái)設(shè)置紅點(diǎn)的frame
App啟動(dòng)過(guò)程中,部分View可能無(wú)法實(shí)時(shí)獲取到frame
// 只有等執(zhí)行完 UIViewController 的 viewDidAppear 方法以后,才能獲取到正確的值,在viewDidLoad等地方 frame Size 為 0,例如: UIApplication.shared.statusBarFrame
廢棄UIWebView
查看API可以看到:iOS 2.0 到 iOS 11.0
在12.0就已經(jīng)被廢棄,部分APP使用webview時(shí), 審核被拒
@available(iOS, introduced: 2.0, deprecated: 12.0, message: "No longer supported; please adopt WKWebView.")
open class UIWebView : UIView, NSCoding, UIScrollViewDelegate {
.........
.........
.........
}
CNCopyCurrentNetworkInfo
iOS13 以后只有開(kāi)啟了 Access WiFi Information capability,才能獲取到 SSID 和 BSSID wi-fi or wlan 相關(guān)使用變更
最近收到了蘋(píng)果的郵件,說(shuō)獲取WiFi SSID的接口CNCopyCurrentNetworkInfo 不再返回SSID的值。不仔細(xì)看還真會(huì)被嚇一跳,對(duì)物聯(lián)網(wǎng)的相關(guān)APP簡(jiǎn)直是炸彈。仔細(xì)看郵件還好說(shuō)明了可以先獲取用戶(hù)位置權(quán)限才能返回SSID。
注意:目本身已經(jīng)打開(kāi)位置權(quán)限,則可以直接獲取
- (NSString*) getWifiSsid {
if (@available(iOS 13.0, *)) {
//用戶(hù)明確拒絕,可以彈窗提示用戶(hù)到設(shè)置中手動(dòng)打開(kāi)權(quán)限
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
NSLog(@"User has explicitly denied authorization for this application, or location services are disabled in Settings.");
//使用下面接口可以打開(kāi)當(dāng)前應(yīng)用的設(shè)置頁(yè)面
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
return nil;
}
CLLocationManager* cllocation = [[CLLocationManager alloc] init];
if(![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined){
//彈框提示用戶(hù)是否開(kāi)啟位置權(quán)限
[cllocation requestWhenInUseAuthorization];
usleep(50);
//遞歸等待用戶(hù)選選擇
return [self getWifiSsidWithCallback:callback];
}
}
NSString *wifiName = nil;
CFArrayRef wifiInterfaces = CNCopySupportedInterfaces();
if (!wifiInterfaces) {
return nil;
}
NSArray *interfaces = (__bridge NSArray *)wifiInterfaces;
for (NSString *interfaceName in interfaces) {
CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName));
if (dictRef) {
NSDictionary *networkInfo = (__bridge NSDictionary *)dictRef;
NSLog(@"network info -> %@", networkInfo);
wifiName = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID];
CFRelease(dictRef);
}
}
CFRelease(wifiInterfaces);
return wifiName;
}
同意打?。喝缦?/p>
network info -> {
BSSID = "44:dd:fb:43:91:ff";
SSID = "Asus_c039";
SSIDDATA = <41737573 5f633033 39>;
}
不同意
network info -> {
BSSID = "00:00:00:00:00:00";
SSID = WLAN;
SSIDDATA = <574c414e>;
}
持續(xù)更新中…
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS開(kāi)發(fā)之自定義UITextField的方法
UITextField是IOS開(kāi)發(fā)中用戶(hù)交互中重要的一個(gè)控件,常被用來(lái)做賬號(hào)密碼框,輸入信息框等。本文給大家介紹iOS開(kāi)發(fā)之自定義UITextField的方法,感興趣的朋友一起學(xué)習(xí)吧2016-05-05
利用iOS實(shí)現(xiàn)系統(tǒng)相冊(cè)大圖瀏覽功能詳解
查看大圖是們?nèi)粘i_(kāi)發(fā)中經(jīng)常會(huì)遇到的一個(gè)需求,下面這篇文章主要給大家介紹了關(guān)于利用iOS實(shí)現(xiàn)系統(tǒng)相冊(cè)大圖瀏覽功能的相關(guān)資料,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來(lái)一起看看吧。2017-09-09
ios利用正則表達(dá)式判斷手機(jī)號(hào)碼格式是否正確的實(shí)例
下面小編就為大家分享一篇ios利用正則表達(dá)式判斷手機(jī)號(hào)碼格式是否正確的實(shí)例,具有很好的參考價(jià)值。希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-11-11
iOS App開(kāi)發(fā)中UISearchBar搜索欄組件的基本用法整理
iOS開(kāi)發(fā)組件中自帶的UISearchBar提供了很多基礎(chǔ)和好用的搜索欄UI功能,下面就來(lái)總結(jié)一下iOS App開(kāi)發(fā)中UISearchBar搜索欄組件的基本用法整理,需要的朋友可以參考下2016-05-05
IOS TextFiled與TextView 鍵盤(pán)的收起以及處理鍵盤(pán)遮擋
這篇文章主要介紹了IOS TextFiled與TextView 鍵盤(pán)的收起以及處理鍵盤(pán)遮擋的相關(guān)資料,需要的朋友可以參考下2016-12-12
iOS 對(duì)plist文件進(jìn)行讀寫(xiě),增刪改查的實(shí)例
下面小編就為大家?guī)?lái)一篇iOS 對(duì)plist文件進(jìn)行讀寫(xiě),增刪改查的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02

