ios - Open WebView links in Safari -
app run it loads the web page in the Safari, the first loads I Here is some code Webviewcontroller.m - @end Loading because the first page instead Safari your Remove this line from your your then add ;. Safari application, first set the This method will be called every time when UIWebView and external code in
is WebView open in Safari?
#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]; }
UIWebView this line of code in your application:
[[UIApplication sharedApplication] openURL: URL];
viewDidLoad method.
WebView
Inside viewDidLoad Method
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; }
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
Post a Comment