iOS13出來有一段時(shí)間了,最近才開始適配,著實(shí)有些晚了,記錄下自己踩到的坑; 持續(xù)更新...
[2019-08-26 ]: Xcode11 & iOS13真機(jī)'UIAlertView' Crash
*** Terminating app due to uncaught exception 'NSObjectNotAvailableException', reason: 'UIAlertView is deprecated and unavailable for UIScene based applications, please use UIAlertController!'
處理方式就顯而易見了贴硫,替換成UIAlertController
,看來標(biāo)記為廢棄的還是盡量不用為好
[2019-08-19]: iOS 13 beta 7 : 子線程Crash伊者,App仍存活
2019-08-15日Apple發(fā)布了iOS 13 beta 7
, 收到一系列新的反饋英遭,其中有一個(gè)問題比較奇怪,在觸發(fā)某些Case后亦渗,相關(guān)功能穩(wěn)定不可用挖诸,Debug測(cè)試發(fā)現(xiàn)在iOS 13 beta 7
中,某個(gè)子線程遇到Swift強(qiáng)制解包(nil!)
不會(huì)導(dǎo)致整個(gè)App Crash掉央碟,主線程卡頓一段時(shí)間后税灌,仍然可以正常的操作,但是依賴Crash的子線程的任務(wù)會(huì)掛掉亿虽,具體原因暫時(shí)未知菱涤,還在調(diào)研。
[2019-07-30]: -w -Xanalyzer -analyzer-disable-all-checks
在Xcode11-beta4
(僅在4洛勉,1粘秆、2、3&5沒有這個(gè)問題)中可能會(huì)遇到如下報(bào)錯(cuò)
<unknown>:0: error: unknown argument: '-w'
<unknown>:0: error: unknown argument: '-Xanalyzer'
<unknown>:0: error: unknown argument: '-analyzer-disable-all-checks'
Command CompileSwiftSources failed with a nonzero exit code
這個(gè)是因?yàn)镃ocoapods的inhibit_all_warnings!
收毫、:inhibit_warnings => true
導(dǎo)致的攻走,需要到Podfiile中注釋掉所有相關(guān)部分,如:
修改前:
# 全局關(guān)閉警告
inhibit_all_warnings!
pod 'RxSwift', :inhibit_warnings => true
修改后:
# 全局關(guān)閉警告
# inhibit_all_warnings!
pod 'RxSwift'#, :inhibit_warnings => true
參考鏈接: https://github.com/CocoaPods/CocoaPods/issues/9013
[2019-07-16]: StatusBar
之前可以使用如下方法獲取或修改StatusBar的一些屬性
if let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow {
statusBarWindow.alpha = 1 - statusBarWindow.alpha
}
現(xiàn)在會(huì)報(bào)錯(cuò)
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'
找了很久找到一些獲取屬性的方式此再,但是現(xiàn)在沒法更改屬性了昔搂,無論是直接改還是setValue(_: forKey:),都會(huì)崩掉输拇。
if #available(iOS 13.0, *) {
#if swift(>=5.1)
if let statusBarManager = UIApplication.shared.keyWindow?.windowScene?.statusBarManager,
let localStatusBar = statusBarManager.perform(Selector(("createLocalStatusBar")))?.takeRetainedValue()
as? UIView,
let statusBar = localStatusBar.perform(Selector(("statusBar")))?.takeRetainedValue() as? UIView,
let _statusBar = statusBar.value(forKey: "_statusBar") as? UIView {
print(localStatusBar, statusBar, _statusBar)
}
#endif
} else {
// Fallback on earlier versions
if let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow {
statusBarWindow.alpha = 1 - statusBarWindow.alpha
}
}
私有屬性KVC
使用私有API一時(shí)爽摘符,
一直使用一直爽蘋果一禁火葬場(chǎng)
iOS不再支持使用valueForKey
、setValue: forKey
等方式處理一些私有屬性策吠,下面列舉一下已經(jīng)發(fā)現(xiàn)的和替換方案逛裤。
UITextFiled: _placeholderLabel.textColor
// old code Swift
textFiled.setValue(UIColor.red, forKey: "_placeholderLabel.textColor")
替換方案
textFiled.attributedPlaceholder = NSMutableAttributedString(
string: "Placeholder",
attributes: [.foregroundColor: UIColor.red]
)
UISearchBar: value(forKey: "_searchField")
// old code Swift
searchBar.value(forKey: "_searchField")
替換方案
#if swift(<5.1)
print(searchBar.value(forKey: "_searchField") ?? "Read Error")
#else
print(searchBar.searchTextField)
#endif
樣式 Or 行為變更
UISegmentedControl 樣式變更下圖
處理方案:
// swift 使用下面的方法自定義樣式
control.setTitleTextAttributes(
[.foregroundColor: UIColor.white],
for: .selected)
control.setBackgroundImage(
UIImage(named: "iamgeName"),
for: .normal,
barMetrics: .default)
control.setDividerImage(
UIImage(named: "iamgeName"),
forLeftSegmentState: .normal,
rightSegmentState: .normal,
barMetrics: .default)
UIModalPresentationStyle
ViewController
的 present
的默認(rèn)style
變了,如下圖: