2016-09-06 261 views
0

下面是代碼我曾嘗試:的UIWebView顯示加載URL後白屏

HTMLBrowserViewController.h 
IBOutlet UIWebView * webControl; 

HTMLBrowserViewController.m 

webControl.scalesPageToFit = YES; 

webControl.contentMode = UIViewContentModeScaleAspectFit; 

webControl.delegate = self; 

NSURL *url1=[NSURL URLWithString:webUrl]; 

NSURLRequest *requestObject=[NSURLRequest requestWithURL:url1 cachePolicy:NSURLCacheStorageAllowed timeoutInterval:15];  

[webControl loadRequest:requestObject]; 
+0

檢查您的url1是否輸出 –

+0

作爲Anbu.Karthik建議檢查在一個正常的瀏覽器中的網址或設置爲webUrl stackoverflow.com測試。然後檢查你的IBOutlet是否連接,如果是這樣,檢查是否調用UIWebView委託方法 – matteok

+0

姊妹顯示你的url1.I將幫助你。 – user3182143

回答

1

添加NSAppTransportSecurity在應用程序的.plist文件

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

Check this link transport Security has Blocked a cleartext HTTP

+0

我已經添加了這段代碼。 –

+0

@SanjanaBabhulgaonkar我認爲檢查你的網址可能會導致網址問題。你的網址是什麼? –

+0

姐姐我在等你的回覆。請給webUrl和url1進行檢查。 – user3182143

0

試試這個:

NSString *encodedString=[urlString  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    NSLog(@"urlString %@",encodedString); 

    NSURL *url = [NSURL URLWithString:encodedString]; 

    //URL Requst Object 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

    // Set delegete 
    webView.delegate=self; 

    //Load the request in the UIWebView. 
    [webView loadRequest:requestObj];