opening an URL in safari while iPhone button is clicked - iphone

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.

Related

Opening an Native ios App inside an Another App?

i have this idiotic Question .
Is there any way open an another ios Application inside a view controller of a app.
I know we can open a another Ios app if we have url schema and the calling application goes to background and called application goes to background.
Is there any way ?? i just got a dream ,so am asking can we do it??
It is not possible to do it with the iPhone SDK. You can do this though by using Private APIs.
You can make it work on jailbroken devices.
But if you want to call native social apps like facebook or twitter you should use this code.
It works and apple approves it.
NSURL *fbNativeAppURL = [NSURL URLWithString:#"fb://"];
if ( [[UIApplication sharedApplication] canOpenURL:fbNativeAppURL])
{
[[UIApplication sharedApplication] openURL:fbNativeAppURL];
}
or
NSURL *twNativeAppURL = [NSURL URLWithString:#"twitter://"];
if ( [[UIApplication sharedApplication] canOpenURL:twNativeAppURL])
{
[[UIApplication sharedApplication] openURL:twNativeAppURL];
}

Open iTunes links to apps in UIWebView if app is already installed

If I open this url in Safari iOS would check if I have this app installed. If it is - the app will be launched otherwise I will be redirected to the AppStore app.
Is it possible to make UIWebView to do the same thing?
The key thing is that system checks weather the app installed and has CFBundleURLTypes registered to respond.
EDIT:
Sorry guys I was wrong with identifying the problem. There is actually another link that redirects to the direct (local) link that is registered for the app. I catch this now in
-(BOOL) webView:(UIWebView *)inWeb
shouldStartLoadWithRequest:(NSURLRequest *)inRequest
navigationType:(UIWebViewNavigationType)inType
and call
[[UIApplication sharedApplication] openURL:url]
If UIApplication openURL does what you want (open the app page in App Store or open the app if it's installed; I guess it will do so) you can "steal" the url opening event in the UIWebView in the following way:
// myWebView will be your initialized web view
[myWebView setDelegate:self];
// implement this method in the owning class
-(BOOL) webView:(UIWebView *)inWeb
shouldStartLoadWithRequest:(NSURLRequest *)inRequest
navigationType:(UIWebViewNavigationType)inType
{
if (inType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
This will open all links clicked in the web view in Safari / App Store / default handling app. If you want to open only iTunes links this way, you might want to implement some URL parsing in this method and redirect only those links. If you return YES, the default handler will be called i.e. the link will be opened in the web view.
The behavior you describe isn't how it currently works on iOS 5.1
clicking on iTMS link a second time will still launch App Store.
This may help you with detecting if a app already installed
https://stackoverflow.com/a/5746603/515359

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"]];

Open web browser on launch of App

I need to know how to have an iphone app do nothing but open the web browser as soon as it starts. I know the code needed to open a broswer.. its
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
[[UIApplication sharedApplication] openURL:url];
My problem is I don't know where to put this code. Ive tried putting it in main.m but it either errors or does nothing. I'd like to avoid needing to use a button. I'd prefer it be automatic as soon as the app is launched. I also need to image this to a HDMI TV and once again, I know the code for this.. I just don't know where it should be put, as I also want it to begin as soon as the app is started.
Thanks.
If you plan to submit this app to the App Store I've got bad news for you, Apple will reject your app if all it does is open a website.
But back to your question place the code in app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
[[UIApplication sharedApplication] openURL:url];
}

Restarting iPhone application after [UIApplication sharedApplication] openURL

As title says I'd like to know how to restart my iPhone app after doing this:
[[UIApplication sharedApplication] openURL:[NSURL UrlWithString:#"tel://0123456789"]]
It seems pretty simple as I saw many topics also talking about restoring the very state of the application when openURL is called, but I can't find how to simply restart the app when the calling is finished.
Is it supposed to be the default behavior? As for me, the iPhone opens Favorites after call is finished, I don't know why.
You can't. Starting an app is solely user's responsibility - which I consider a good thing.
check the discussion here: https://devforums.apple.com/message/128046#128046
create a UIWebView to load the phone url like this:
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
just use
[[UIApplication sharedApplication] openURL:[NSURL UrlWithString:#"telprompt://0123456789"]]
It will return to the app after call finished
You can't restart an app after a phone call, as your app has terminated and your code is no longer being run.
If you want to restart after the user visits a webpage, you can put a link with a custom scheme in that webpage, and register it with your app. The user can then tap the link to open your app again.