項(xiàng)目適配iOS9遇到的一些問題及解決辦法

1.網(wǎng)絡(luò)請(qǐng)求報(bào)錯(cuò)。升級(jí)Xcode 7.0發(fā)現(xiàn)網(wǎng)絡(luò)訪問失敗。

? ?輸出錯(cuò)誤信息The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

原因:iOS9引入了新特性App Transport Security (ATS)。

詳情:App Transport Security (ATS)新特性要求App內(nèi)訪問的網(wǎng)絡(luò)必須使用HTTPS協(xié)議。但是現(xiàn)在公司的項(xiàng)目使用的是HTTP協(xié)議,使用私有加密方式保證數(shù)據(jù)安全。現(xiàn)在也不能馬上改成HTTPS協(xié)議傳輸。

最終找到以下解決辦法:在Info.plist中添加NSAppTransportSecurity類型Dictionary。在NSAppTransportSecurity下添加NSAllowsArbitraryLoads類型Boolean,值設(shè)為YES

2.Scheme白名單問題(無法判斷手機(jī)是否安裝微信等)

-canOpenURL: failed for URL: "weixin://app/wxdaae92a9cfe5d54c/" - error: "This app is not allowed to query for scheme weixin"

搜索后得知近期蘋果公司iOS 9系統(tǒng)策略更新,限制了http協(xié)議的訪問,此外應(yīng)用需要在“Info.plist”中將要使用的URL Schemes列為白名單,才可正常檢查其他應(yīng)用是否安裝.

受此影響,當(dāng)你的應(yīng)用在iOS 9中需要使用微信SDK的相關(guān)能力(分享、收藏、支付、登錄等)時(shí),需要在“Info.plist”里增加如下代碼:注意:截圖來自微信開放平臺(tái),里面已經(jīng)包含第一個(gè)問題的解決完成后需使用Xcode 7編譯。

如果你在模擬器上運(yùn)行可以能還會(huì)有以下報(bào)錯(cuò):

-canOpenURL: failed for URL: "weixin://app/wxdaae92a9cfe5d54c/" - error: "(null)"

這是因?yàn)槟M器上并沒有安裝微信,如果運(yùn)行到真機(jī)上就不會(huì)有報(bào)錯(cuò)了。

請(qǐng)注意:未升級(jí)到微信客戶端6.2.5及以上版本的用戶,在iOS 9下使用到微信相關(guān)功能時(shí),仍可能無法成功。下面整理一些常用的白名單LSApplicationQueriesSchemesmqqOpensdkSSoLoginmqzonesinaweiboalipayauthalipaysafepaymqqmqqapimqqopensdkapiV3mqqopensdkapiV2mqqapiwalletmqqwpamqqbrowserwtloginmqq2weixinwechatqq登錄綁定,qq支付,qq分享微信支付,微信登錄綁定新浪登錄綁定支付寶支付,支付寶登錄綁定

3.Bitcode問題(通俗解釋:在線版安卓ART模式)報(bào)錯(cuò)如下ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/Developer/Library/Frameworks'ld: -bundle and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used togetherclang: error: linker command failed with exit code 1 (use -v to see invocation)Bitcode

報(bào)錯(cuò)原因:Xcode7 及以上版本會(huì)默認(rèn)開啟 bitcode 。

bitcode具體是什么就不解釋了。解決方法:1.更新library使包含Bitcode,否則會(huì)出現(xiàn)以上的警告。2.關(guān)閉Bitcode,簡(jiǎn)單粗暴。Build Settings”->”Enable Bitcode”改成"NO"。4.項(xiàng)目運(yùn)行報(bào)錯(cuò)如下: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

出錯(cuò)原因:設(shè)置app的狀態(tài)欄樣式的使用使用了舊的方式,在info.plist里面設(shè)置了View controller-based status bar appearance為NO,默認(rèn)為YES,一般式iOS6的時(shí)候使用這種方式,iOS7,8也兼容,但是到了iOS9就報(bào)了警告。

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];

以前我們通過上面代碼改變狀態(tài)了顏色,iOS9以后點(diǎn)進(jìn)去看api發(fā)現(xiàn)如下說明

// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system.

@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]");

- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]");

解決辦法:

修改方式將View controller-based status bar appearance設(shè)置為YES,然后使用新的方式來實(shí)現(xiàn)狀態(tài)欄的樣式。

- (UIStatusBarStyle)preferredStatusBarStyle;

- (UIViewController *)childViewControllerForStatusBarStyle;

- (void)setNeedsStatusBarAppearanceUpdate

2015.09.21更新

5 directory not found for option問題

警告如下:

ld: warning: directory not found for option '-F/Applications/Xcode 7.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/Developer/Library/Frameworks'

問題原因:Xcode7將framworks位置改變了。

解決方法:

點(diǎn)擊項(xiàng)目,選擇 Targets->xxxTests

選擇build setting ,找到 Frameworks Search Path 或者 Library Search Paths

刪除$(SDKROOT)/Developer/Library/Frameworks,

或者使用$(PLATFORM_DIR)/Developer/Library/Frameworks替換

framworks位置改變

暫時(shí)就這些,還有其他問題會(huì)繼續(xù)更新

如果你們還有其他問題請(qǐng)參考:https://github.com/ChenYilong/iOS9AdaptationTips

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

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