0

i am trying to launch a URL with WebView on xCode 7 and my issue is that it always appears a blank white page when i hit the Build button.

Below is the code:

ViewConntroller.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;


@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *fullURL= @"http://www.google.com";

    NSURL *url = [NSURL URLWithString:fullURL];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:requestObj];

}


- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [_activityIndicator startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_activityIndicator stopAnimating]; _activityIndicator.hidden = TRUE;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

@end
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Leonidas
  • 45
  • 1
  • 1
  • 8

1 Answers1

1

Xcode 7 and iOS 9 introduced a system known as App Transport Security (ATS). This will prevent the app from loading certain web resources and in a WebView this will lead to a blank screen.

The gist of this is you must choose from one of the following:

a) Only use HTTPS resources -> Perhaps try https://www.google.com (not tested this myself).

b) Selectively choose which NON-HTTPS resources to use -> See here for explanation.

c) Disable ATS all together -> Not advised, but unavoidable sometimes. To do this, find your Info.plist file and add the following:

NSAppTransportSecurity (Dictionary) | ----> NSAllowsArbitraryLoads(Bool) = YES

OR in source code view (right click on file > Open As > Source Code):

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

See here for more.

Check the console of Xcode when running the app to see if you get an error message that says you must temporarily white list this site.

Community
  • 1
  • 1
barnabus
  • 862
  • 7
  • 26