即使在加载网址后,UIWebview仍显示空白屏幕

时间:2016-07-27 05:17:30

标签: ios objective-c uiwebview

我有一个html页面,在提交按钮上单击我需要调用支付网关URL 我正在使用NSMutableURLRequest并传递帖子数据,我正在使用
来调用URL 请在下面找到代码:

NSDictionary *parameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:currency_code,apikey,merchant_id,checksum_method,authorize_user,ip_address,hash,NB, nil] forKeys:[NSArray arrayWithObjects:@"currency_code",@"apikey",@"merchant_id",@"checksum_method",@"authorize_user",@"ip_address",@"checksum",@"cardType", nil]];
__block NSString *post = @"";
[parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
    if ([post isEqualToString:@""]) {
        post = [NSString stringWithFormat:@"%@=%@",key,obj];
    } else {
        post = [NSString stringWithFormat:@"%@&%@=%@",post,key,obj];
    }
}];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%ld",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://pay.sandbox.shmart.in/pay_merchant/js"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

[webview loadRequest:request];

webViewDidFinishLoad也被调用,但它显示我一个空白的白色屏幕 什么是问题的任何想法。

4 个答案:

答案 0 :(得分:3)

传输安全已阻止明文HTTP(http://)资源加载,因为它不安全,您需要添加You have to set the NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your .plist文件`。,并尝试查看此link

答案 1 :(得分:1)

我也遇到了同样的问题,并通过从网址中删除空格和不需要的字符来解决了这个问题。

如果仅尝试加载HTTP URL,请在info.plist的“应用传输安全性设置”中检查并启用AllowArbitaryLoad。 您可以参考以下链接。

Transport security has blocked a cleartext HTTP

如果您使用的是https URL,请确保该URL在Safari和Chrome浏览器响应模式下均可正常加载。

有时,网站会将响应URL加载到iFrame中。因此请检查传递正确的URL。

此外,在传递给UIWebView之前,请打印URL,有时URL应该有空格,并且应为&。因此将其删除并传递到WebView中。

serviceBookingUrl = [NSURLRequest requestWithURL: [NSURL URLWithString:[websiteURL stringByReplacingOccurrencesOfString:@"&" withString:@"&"]]];
[PrimaryWebView loadRequest: serviceBookingUrl];

其中websiteURL是网站URL。

答案 2 :(得分:0)

enter image description here

像图片一样添加,确保你的网址在safair中正常

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

答案 3 :(得分:0)

您的代码应该是,

  UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 300, 500)];

[self.view addSubview:tempWebview];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];

[tempWebview loadRequest:request];

Your url must support mobile web browser

因此,请检查您的网址和参数是否有效,并且您已提出有效请求。

相关问题