Mats Raemen
Mats Raemen

Reputation: 1812

iOS app with UIWebView gives blank screen

I am new to iOS development and xCode and wanted to make a simple app containing a fullscreen webview.

I found the following tutorial: webview tutorial

I followed the steps mentioned and when I ran the app in the simulator, it just gave me a blank screen.

I then downloaded the source code, ran that and I still get a blank screen. So something tells me it has nothing to do with the code, but maybe with some sort of configuration? As far as I can tell I have a WiFi connection as the wifi icon is in my status bar in the top of the screen. If necessary, I will happily post any relevant code.

Thanks!

Upvotes: 1

Views: 668

Answers (3)

Chandu
Chandu

Reputation: 82

UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width ,self.view.frame.size.height)];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[webview loadRequest:nsrequest];
[self.view addSubview:webview];

Try this, definitely helps to you.

Upvotes: 0

Vishnu gondlekar
Vishnu gondlekar

Reputation: 3956

It is happening because you are trying to send http request and App transport security of iOS allows only https request unless you explicitly specify in the plist. You can either filter particular domain from the above check using

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>yourdomain.com</key>
        <dict>
            <!--Include to allow subdomains-->
            <key>NSIncludesSubdomains</key>
            <true/>
            <!--Include to allow HTTP requests-->
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <!--Include to specify minimum TLS version-->
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
</dict>

Or you can disable entire transport security by adding following to your info.plist file.

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

Upvotes: 1

Anticro
Anticro

Reputation: 803

Instead of "http://..." use a "https://" URL. IOS has a relatively new restriction that forbids loading of unsecured URLs, which must be removed by the "AllowArbitaryLoads=YES" key in the Info.plist. (Create the key "App Transport Security", unfold it and create the ArbitaryLoads one with the BOOL value YES)

Upvotes: 1

Related Questions