ios - Open WebView links in Safari -


app run it loads the web page in the Safari, the first loads I UIWebView and external code in is WebView open in Safari?

Here is some code Webviewcontroller.m -

  #import "WebViewController.h" @ implementation WebViewController @synthesize webView; - (id) initWithNibName: (NSString *) nibNameOrNil Bundle: (NSBundle *) nibBundleOrNil {if (self = [super initWithNibName: nibNameOrNil Bundle: nibBundleOrNil]) {// initialization code} return self; } / * If you need to set up additional setup after loading the view, overdried viewdownload. * / - (zero) viewDidoad {NSString * urlAddress = @ "URL link goes here"; // Create URL object NSURL * url = [NSURL URLWithString: urlAddress]; [[UIApplication shared application] Open URL: URL]; // URL Requested Item NSURLRequest * requestObj = [NSRR Request Request With url: url]; // Load request in UIWebView [WebView loadRequest: requestObj]; }   

@end

Loading because the first page instead Safari your UIWebView this line of code in your application:

  [[UIApplication sharedApplication] openURL: URL];   

Remove this line from your viewDidLoad method.

your WebView Inside viewDidLoad Method

then add ;. Safari application, first set the webView.delegate = Your view controller as a representative for WebView with the following code for your ViewController :

  - (Bool) Webview: (UIWebView *) WebView shouldStartLoadWithRequest: (NSURLRequest *) Request navigationType: (UIWebViewNavigationType) navigationType {if (Navigation type == UIWebViewNavigationTypeLinkClicked) {[UIApplication shared application] openURL: request.URL]; no return; } Yes return; }   

This method will be called every time when webView is about to begin loading a request. What it does, it checks that the request was initiated by the user through click. If this happens, then opens the safari and loads the request there. Any other requests that were not initiated with a click were loaded in your application, such as the request for your start page.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -