微信支付或访问一些网站时报错:
SDKSample[669:19724] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
原因是 :
IOS9 中将 http 请求改成了 HTTPS(加密) 的方式
解决:
在项目的info.plist 文件里加上如下节点:
NSAppTransportSecurity - NSAllowsArbitraryLoads
这个子节点的意思是:是否允许任性的加载? 设为 YES 的话就将禁用了 AppTransportSecurity 转而使用用户自定义的设置。
当 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