本文介紹了支持xcode10和適配iphone xs max、iphone xr的方法,分享給大家,具體如下,
目前我們項(xiàng)目已做了xcode10(swift4.0)和新機(jī)型的適配,總結(jié)一下遇到的問(wèn)題和修改的內(nèi)容,希望幫助到其他人,如果您有不同的看法或遺漏,歡迎指出!
1.第三方庫(kù)編譯報(bào)錯(cuò)
如果項(xiàng)目里用到了mixpanel-swift和swiftlint,這兩個(gè)在xcode10上會(huì)報(bào)錯(cuò),目前作者已提交新版本分別是2.4.5和0.27.0,更新后即可解決報(bào)錯(cuò)。
2.library not found for - lstdc++.6.0.9
pod工程編譯通過(guò)后會(huì)進(jìn)行主工程的編譯,如果依賴了libstdc++.tbd和libstdc++.6.0.9.tbd,就會(huì)報(bào)這個(gè)error,原因是蘋果在xcode10和ios12中移除了libstdc++這個(gè)庫(kù),由libc++這個(gè)庫(kù)取而代之,蘋果的解釋是libstdc++已經(jīng)標(biāo)記為廢棄有5年了,建議大家使用經(jīng)過(guò)了llvm優(yōu)化過(guò)并且全面支持c++11的libc++庫(kù)。
臨時(shí)的解決方法就是把libstdc++.6.0.9.tbd這個(gè)文件導(dǎo)入到xcode10中,分別放到以下目錄 /applications/xcode.app/contents/developer/platforms/iphoneos.platform/developer/sdks/iphoneos.sdk/usr/lib/ 和 /applications/xcode.app/contents/developer/platforms/iphonesimulator.platform/developer/sdks/iphonesimulator.sdk/usr/lib/ 這時(shí)編譯可以通過(guò)。
但這只是臨時(shí)的解決方案,如果你自己的業(yè)務(wù)模塊使用了libstdc++,那么就把模塊代碼重新調(diào)整為依賴libc++,然后重新檢查是否存在問(wèn)題,重新編譯。如果你引用的第三方廠商提供的sdk中依賴了libstdc++,那么抓緊聯(lián)系廠商,要求版本升級(jí)。
3.enum case '...' not found in type '...'
解決好上面兩個(gè)報(bào)錯(cuò),編譯程序時(shí)還會(huì)顯示這個(gè)error,具體場(chǎng)景如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
posvisitquestiontype: string { case text case textarea = "text_area" case dropdownlist = "drop_down_list" case radiobutton = "radio_button" } let type: posvisitquestiontype! ... switch type { case .text, .textarea: errortext = nslocalizedstring( "please enter the following options" , comment: "" ) case .dropdownlist, .radiobutton: errortext = nslocalizedstring( "click the right button to get current location" , comment: "" ) default : break } |
xcode10建議每個(gè)case 情況下加“?”
原因可能是 type是可選的,所以每個(gè)case情況要與type類型保持一致,所以提示加 “?”,可能是xcode10編譯器更新的原因。
修改的方法是如果確定type會(huì)被賦值,那在定義的時(shí)候就把“!”去掉,如果不確定type是否有值就按照xcode提示修改。
4.適配iphone xs max、iphone xr
我們項(xiàng)目在獲取機(jī)型等信息用的是devicekit這個(gè)第三方庫(kù),所以也需要更新一下才能獲取到新機(jī)型的信息,最新版是1.8.1。在最新版有這樣一個(gè)變量
1
2
3
4
|
/// all face id capable devices static public var allfaceidcapabledevices: [device] { return [.iphonex, .iphonexs, .iphonexsmax, .iphonexr] } |
由于iphone x、iphone xs、iphone xs max、iphone xr這些機(jī)型的navigationbar高度以及tabbar高度都一致,所以可以用allfaceidcapabledevices是否包含當(dāng)前設(shè)備,來(lái)判斷當(dāng)前設(shè)備是否有“齊劉海”。
示例:
1
2
3
4
5
6
7
8
9
|
static let faceiddevicearray = device.allfaceidcapabledevices static let navigationheight: cgfloat = { if faceiddevicearray.contains(currentdevice) { return faceiddevicenavheight } else { return ordinarydevicenavheight } }() |
同時(shí)devicekit中也提供這樣一個(gè)方法,運(yùn)行模擬器的時(shí)候調(diào)用,也會(huì)返回真實(shí)的設(shè)備名稱
1
2
3
4
5
6
7
8
|
/// get the real device from a device. if the device is a an iphone8plus simulator this function returns .iphone8plus (the real device). /// if the parameter is a real device, this function returns just that passed parameter. /// /// - parameter device: a device. /// /// - returns: the underlying device if the `device` is a `simulator`, /// otherwise return the `device`. public static func realdevice(from device: devicekit.device) -> devicekit.device |
示例:
1
2
3
4
|
static let currentdevice = device.realdevice(from: device()) if currentdevice == .iphonex {} // 取代以下寫法 if device() == .iphonex || device() == .simulator(.iphonex) {} |
最后別忘了再切兩張啟動(dòng)圖,因?yàn)閕phone xs和尺寸和iphone x是一樣的,所以iphone xs可以忽略
iphone xr:828px x 1792px
iphone xs max: 1242px x 2688px
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)服務(wù)器之家的支持。
原文鏈接:https://www.jianshu.com/p/24920e577e07