1.網(wǎng)絡(luò)請求報錯。
升級Xcode 7.0發(fā)現(xiàn)網(wǎng)絡(luò)訪問失敗。
輸出錯誤信息:
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)在公司的項目使用的是HTTP協(xié)議,使用私有加密方式保證數(shù)據(jù)安全。現(xiàn)在也不能馬上改成HTTPS協(xié)議傳輸。
最終找到以下解決辦法:
在Info.plist中添加NSAppTransportSecurity類型Dictionary。
在NSAppTransportSecurity下添加NSAllowsArbitraryLoads類型Boolean,值設(shè)為YES
2.Scheme白名單問題(無法判斷手機是否安裝微信等)
-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)用是否安裝。
受此影響,當你的應(yīng)用在iOS 9中需要使用微信SDK的相關(guān)能力(分享、收藏、支付、登錄等)時,需要在“Info.plist”里增加如下代碼:
注意:截圖來自微信開放平臺,里面已經(jīng)包含第一個問題的解決
完成后需使用Xcode 7編譯。
如果你在模擬器上運行可以能還會有以下報錯:
-canOpenURL: failed for URL: "weixin://app/wxdaae92a9cfe5d54c/" - error: "(null)"
這是因為模擬器上并沒有安裝微信,如果運行到真機上就不會有報錯了。
請注意:未升級到微信客戶端6.2.5及以上版本的用戶,在iOS 9下使用到微信相關(guān)功能時,仍可能無法成功。
下面整理一些常用的白名單
3.Bitcode問題(通俗解釋:在線版安卓ART模式)
報錯如下
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 together
clang: error: linker command failed with exit code 1 (use -v to see invocation)
原因:Xcode7 及以上版本會默認開啟 bitcode 。
bitcode具體是什么就不解釋了。
解決方法:
1.更新library使包含Bitcode,否則會出現(xiàn)以上的警告。
2.關(guān)閉Bitcode,簡單粗暴。
Build Settings”->”Enable Bitcode”改成"NO"。
4.項目運行報錯如下
:CGContextSaveGState: invalid context0x0. If you want to see the backtrace, please setCG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextTranslateCTM: invalid context0x0. If you want to see the backtrace, please setCG_CONTEXT_SHOW_BACKTRACE environmental variable.
:CGContextRestoreGState: invalid context0x0. If you want to see the backtrace, please setCG_CONTEXT_SHOW_BACKTRACE environmental variable.
出錯原因:設(shè)置app的狀態(tài)欄樣式的使用使用了舊的方式,在info.plist里面設(shè)置了View controller-based status
bar appearance為NO,默認為YES,一般式iOS6的時候使用這種方式,iOS7,8也兼容,但是到了iOS9就報了警告。
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
以前我們通過上面代碼改變狀態(tài)了顏色,iOS9以后點進去看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,然后使用新的方式來實現(xiàn)狀態(tài)欄的樣式。
- (UIStatusBarStyle)preferredStatusBarStyle;
- (UIViewController *)childViewControllerForStatusBarStyle;
- (void)setNeedsStatusBarAppearanceUpdate;
5. directory not found for option問題
警告如下:
ld: warning: directory not found for option ‘-F/Applications/Xcode7.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/Developer/Library/Frameworks‘
問題原因:Xcode7將framworks位置改變了。
解決方法:
點擊項目,選擇 Targets->xxxTests , 選擇build setting ,找到 Frameworks Search Path 或者 Library Search Paths 刪除$(SDKROOT)/Developer/Library/Frameworks,或者使用$(PLATFORM_DIR)/Developer/Library/Frameworks替換.