微信支付或訪問一些網站時報錯:ios
SDKSample[669:19724] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)web
緣由是 :微信
IOS9 中將 http 請求改爲了 HTTPS(加密) 的方式
session
解決:
app
在項目的info.plist 文件里加上以下節點:less
NSAppTransportSecurity - NSAllowsArbitraryLoadsdom
這個子節點的意思是:是否容許任性的加載? 設爲 YES 的話就將禁用了 AppTransportSecurity 轉而使用用戶自定義的設置。ide
當 APP 內發起 webView 加載 https 的網頁,則須要在 info.plist 中配置以下,若是網站引用的比較多應該是須要針對每一個網站進行配置。微信支付
參考:網站
iOS 9 and OSX 10.11 require TLSv1.2 SSL for all hosts you plan to request data from unless you specify exception domains in your app's Info.plist file.
The syntax for the Info.plist configuration looks like this:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow insecure HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
If your application (a third-party web browser, for instance) needs to connect to arbitrary hosts, you can configure it like this:
<key>NSAppTransportSecurity</key>
<dict>
<!--Connect to anything (this is probably BAD)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
If you're having to do this, it's probably best to update your servers to use TLSv1.2 and SSL, if they're not already doing so. This should be considered a temporary workaround.
//[WXApi sendReq:req] 不跳轉微信支付
能夠嘗試用 [WXApi safeSendReq:req]; 跳轉微信支付,致使不跳轉的緣由多是由於項目開發過程當中,以前應用了微信的shareSDK(沒有支付功能),如今和微信支付的SDK衝突了。
解決:能夠刪除原來的 shareSDK 從新引入 支付的SDK。
//onResp:(BaseResp*)resp 不執行
緣由:微信支付的SDK沒有代理,因此,你想獲取支付後的結果的返回信息,須要去 AppDelegate 裏,添加以下代碼,添加微信的代理:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [WXApi handleOpenURL:url delegate:self];
//或者把回調方法寫到其餘單獨的類裏面
// WXPay *wxpay=[[WXPay alloc]init];
// return [WXApi handleOpenURL:url delegate:wxpay];
}
而後,再實現這個方法:
-(void) onResp:(BaseResp*)resp
ps:
http://stackoverflow.com/questions/30739473/nsurlsession-nsurlconnection-http-load-failed-on-ios-9