Open WebView in Safari - iphone

Can someone tell me how I can make an IBAction that opens the current link in the WebView in Safari.
So ​​that all pages I open that WebView can be opened with that one button in Safari.
Thanks.

- (IBAction)openLink {
NSURL * currentURL = [myWebView.request URL];
[[UIApplication sharedApplication] openURL:currentURL];
}
This should mostly work for URLs loaded via loadRequest: or traversed from there but won't work for other local load methods like loadHTMLString:baseURL:

Related

How to control unwanted Pop-up that appear when making call within app

I am developing an app about making call and returning to app when calling ended. Here is my code;
**callWebview = [[UIWebView alloc] init];
NSURL *telUrl=[NSURL URLWithString:#"tel:4444484"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telUrl]];**
This is ok but when url request is being sent, A pop up appears on the screen.
This is the screenshot when I press the button and run the code at upside;
So , Here is my question;
Can I block this pop up to appear on the screen ?
If I can't how can I change the message body and buttons of this popup ?
Thanks...
If you do not use the UIWebView the message will not appear, but then you will not be able to come beck to the app.
To make a call with out the alert:
NSURL *telUrl=[NSURL URLWithString:#"tel:4444484"];
// Check if the iOS device support dialing a number
if ( [[UIApplication sharedApplication] canOpenURL:telUrl]) {
[[UIApplication sharedApplication] openURL:telUrl];
}
But there is no solution that will do exactly what you desire, so either it is the dialog or no dialog but not retuning to you app.
Try the following instead:
NSURL *telUrl=[NSURL URLWithString:#"tel:4444484"];
[[UIApplication sharedApplication] openURL:telUrl];

iPhone: After UIWebView opens external browser, then returning to app opens it a second time

I have a UIWebView which loads an HTML page which has some links to the App Store (<a herf="http://itunes/bla/bla/bla"> type of links).
Clicking a link, opens external Safari, then opens external App Store app and successfully goes to correct page.
If you then click Home button and return to springboard and click on app again, it will briefly open to the the UIWebView that was displayed and then jump to external Safari and external App Store app again.
If you go back to app one more time it stays in the app.
So what is happening is that returning to app after opening external browser link from UIWebView HTML page, will then jump back to the same link a second time.
Anybody have any ideas what might be causing this?
Am using Xcode 4.2.1 and it happens in simulator as well as on an actual device (iPad 1 with iOS 4.3).
EDIT - SOLUTION:
Ok, here is what I had to do to solve the problem (Thanks to Ben's response below who got me looking at the right areas):
This was my original method:
- (BOOL)webView:(UIWebView *)_webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (didLoad) { //Do not jump to URL when view first loads
return YES;
}
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
And this is my fixed method that does not keep jumping to URL:
- (BOOL)webView:(UIWebView *)_webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (didShowURL) { //Do not jump to URL when returning to app
didShowURL = 0;
return NO;
}
if (didLoad) { //Do not jump to URL when view first loads
return YES;
}
didShowURL = 1;
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
I would suggest using the itms-apps:// protocol for your link. This will send the user directly to the application in the App Store without the need for a redirect.
NSURL *appStoreLink = [NSURL URLWithString:#"itms-apps://itunes.apple.com/us/app/instagram/id389801252?mt=8"];
[[UIApplication sharedApplication] openURL:appStoreLink];
Your webview is being reloaded to its last page (the app store page) and is automatically redirecting the user away again. You just need to make sure that when the app is reloaded it is not trying to load the app store link again.
Depending on your app setup you could use
viewWillAppear
And reload the original HTML page with the links every time the view is brought to the front.

Make Safari Browser appear in iPad/iPhone App

I have an app that I am in the process of writing and I want too have a button on the screen that the user can press to go to a web page in safari. I do not want to use the UIWebView control and make my own browser, I just want the screen to switch to Safari.
Can any give me some tips how to do this?
You should be able to do it with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];

launch browser(safari)inside my app

I have the following code
NSURL *url = [NSURL URLWithString:#"workingUrl"];
[[UIApplication sharedApplication] openURL:url];
which currently loads the url correctly but when the user is done, they have to exit and go back into my app.
How can the browser be loaded from within my app?
Regards
You have to make a little browser yourself. Create a View Controller with a UIWebView and some buttons that tigger it's methods (forward, back, reload, etc).

opening an URL in safari while iPhone button is clicked

I want to add a button to my iPhone application which will open an URL in safari on iPhone when clicked (my application will terminate right?)
Thanks.
Raihan
You need to use - (BOOL)openURL:(NSURL *)url in UIApplication.
UIApplication is a singleton, so your code would look something like this:
NSURL *url;
[[UIApplication sharedApplication] openURL:url];
Your app will close if you are simply opening in Safari.
You can, however, use a WebView control to embed the web browser in your app. This way your app will not terminate.