iOS9 適配

1.網絡請求報錯。
升級Xcode 7.0發現網絡訪問失敗。
輸出錯誤信息

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內訪問的網絡必須使用HTTPS協議。
但是現在公司的項目使用的是HTTP協議,使用私有加密方式保證數據安全。現在也不能馬上改成HTTPS協議傳輸。
最終找到以下解決辦法:
在Info.plist中添加NSAppTransportSecurity類型Dictionary
NSAppTransportSecurity下添加NSAllowsArbitraryLoads類型Boolean,值設爲YES


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

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

搜索後得知

近期蘋果公司iOS 9系統策略更新,限制了http協議的訪問,此外應用需要在“Info.plist”中將要使用的URL Schemes列爲白名單,纔可正常檢查其他應用是否安裝。

受此影響,當你的應用在iOS 9中需要使用微信SDK的相關能力(分享、收藏、支付、登錄等)時,需要在“Info.plist”裏增加如下代碼:

技術分享

注意:截圖來自微信開放平臺,裏面已經包含第一個問題的解決

完成後需使用Xcode 7編譯。

如果你在模擬器上運行可以能還會有以下報錯:

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

這是因爲模擬器上並沒有安裝微信,如果運行到真機上就不會有報錯了。

請注意:未升級到微信客戶端6.2.5及以上版本的用戶,在iOS 9下使用到微信相關功能時,仍可能無法成功。

下面整理一些常用的白名單

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>mqqOpensdkSSoLogin</string>
    <string>mqzone</string>
    <string>sinaweibo</string>
    <string>alipayauth</string>
    <string>alipay</string>
    <string>safepay</string>
    <string>mqq</string>
    <string>mqqapi</string>
    <string>mqqopensdkapiV3</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqapiwallet</string>
    <string>mqqwpa</string>
    <string>mqqbrowser</string>
    <string>wtloginmqq2</string>
    <string>weixin</string>
    <string>wechat</string>
</array>

qq登錄綁定,qq支付,qq分享
微信支付,微信登錄綁定
新浪登錄綁定
支付寶支付,支付寶登錄綁定


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)

技術分享
Bitcode報錯

原因:Xcode7 及以上版本會默認開啓 bitcode 。
bitcode具體是什麼就不解釋了。

解決方法:
1.更新library使包含Bitcode,否則會出現以上的警告。
2.關閉Bitcode,簡單粗暴。

Build Settings”->”Enable Bitcode”改成"NO"。

技術分享

4.項目運行報錯如下

<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
<Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
<Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

出錯原因:設置app的狀態欄樣式的使用使用了舊的方式,在info.plist裏面設置了View controller-based status bar appearance爲NO,默認爲YES,一般式iOS6的時候使用這種方式,iOS7,8也兼容,但是到了iOS9就報了警告。

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];

以前我們通過上面代碼改變狀態了顏色,iOS9以後點進去看api發現如下說明

// 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設置爲YES,然後使用新的方式來實現狀態欄的樣式。

- (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位置改變了。

解決方法:
點擊項目,選擇 Targets->xxxTests
選擇build setting ,找到 Frameworks Search Path 或者 Library Search Paths
刪除$(SDKROOT)/Developer/Library/Frameworks,
或者使用$(PLATFORM_DIR)/Developer/Library/Frameworks替換

技術分享
framworks位置改變

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章