最近作了iOS 9的適配,程序出現大量警告也作了些處理,寫出來分先給你們。php
1、iOS 9適配html
問題一:ios
<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. xcode
出錯緣由:設置app的狀態欄樣式的使用使用了舊的方式,在info.plist裏面設置了View controller-based status bar appearance爲NO,默認爲YES,通常式iOS6的時候使用這種方式,iOS7,8也兼容,可是到了iOS9就報了警告。之前咱們使用代碼爲
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
之前咱們經過上面代碼改變狀態了顏色
解決辦法::
1.刪除 原先的設置代碼
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
2.修改方式將View controller-based status bar appearance設置爲YES,而後使用新的方式來實現狀態欄的樣式。
3.若是你是用
UINavigationController只需要在appdelegate裏面添加 [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack]就行。
問題二:app
-canOpenURL: failed for URL: "weixin://app/wx9c8771d3c07dfd30/" - error: "This app is not allowed to query for scheme weixin"
ide
解決辦法:佈局
<key>LSApplicationQueriesSchemes</key>
<string>urlscheme1</string>
<string>urlscheme2</string>
<string>urlscheme3</string>
<string>urlscheme4</string>
</array>
問題三:
Bitcode問題
緣由:Xcode7 及以上版本會默認開啓 bitcode 。。
解決方法:
1.更新library使包含Bitcode,不然會出現以上的警告。
2.關閉Bitcode,
Build Settings」->」Enable Bitcode」改爲"NO"
問題四:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your
app‘s Info.plist file.
在iOS9中,將原http協議改爲了https協議,使用 TLS1.2 SSL加密請求數據。
解決方法:
在info.plist 加入key
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
2、消除warning
warning 1:
warning :no rule to process file ’…/BBCommmunityVerify.h’ of type sourcecode.c.h for architecture arm64
解決辦法:
能夠看出是某個.h文件出了問題,在Build Phases -> Compile Sources 裏面刪除該文件便可
warning 2:
warning:Automatic Preferred Max Layout Width before iOS 8.0
出現條件:
the warning will appear if
(1) you're using auto layout,
(2) "Automatic" is set for a multiline label [you can check this in the size inspector for the label], and
(3) your deployment target < iOS 8.
上面的意思是警告出現的三個條件
1.使用自動佈局
2.label多行且設置爲.Automatic
3.版本低於iOS 8.
解決辦法:
1 - (void)layoutSubviews {
2 [super layoutSubviews];
3 CGFloat availableLabelWidth = self.label.frame.size.width;
self.label.preferredMaxLayoutWidth = availableLabelWidth;
4 [super layoutSubviews];
5 }
The first call to [super layoutSubviews]
will evaluate the constraints on the label (since it’s a direct subview) and change its frame accordingly. At this point the width is useful, but the height is not; the height was set using the label’s intrinsic content size, which in turn relied on a preferred max layout width value that is now stale.ui
Now we know the actual width of the label, we set that as its max layout width. Internally, this causes the label to invalidate its intrinsic content size; when it’s next queried, it will have the accurate height for its current width. With all layout information in place, we call
[super layoutSubviews]
again.
大概意思是第一個[super layoutSubviews]; 得到width,而後設置self.label.preferredMaxLayoutWidth,第二個用來計算行數。
warning 3:
directory not found for option ‘-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/Developer/Library/Frameworks'
3查找 Library Search Paths 和 Framework Search Paths,-L 找Library Search Paths,-F找Framework Search Paths 刪掉編譯報warning的路徑即OK
warning 4:
warning: Plain Style unsupported in a Navigation Item
解決辦法:
1.找到文件,open as source code 搜索
style=「plain"
2.修改<barButtonItem key="rightBarButtonItem" style="plain" id="juB-DL-F9i">
爲
<barButtonItem key="rightBarButtonItem" id="juB-DL-F9i">
也就是刪除style=「plain"
warning 5:
warning:Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:
錯誤緣由: storyboard中存在沒法得到的控制器。既不是initial控制器,也沒有idenifier;
解決辦法:沒用就刪除,有用的話添加identifier;
warning 6:
warning:Frame for 「Phone Text Filed」 will be different at run time
這個簡單,佈局報黃,更新佈局便可,可設置快捷鍵。。。