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];
}
Related
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];
}
I am able to call from my iphone application by using below code:
NSString *phoneNumber = #"tel://1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Now, i want to know how to return to my application back when the call ends ?
UIWebView *phoneCallWebview = [[UIWebView alloc] init];
// [self.view addSubview:phoneCallWebview];
NSURL *callURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", 9238928399]];
[phoneCallWebview loadRequest:[NSURLRequest requestWithURL:callURL ]];
As far as I'm aware, such interaction is impossible since your application has been demoted to background, and all UI interaction has been delegated to the Phone app, and the user.
I found this SO question
End call, don't return to app automatic in iphone 3.1 version
Which pointed to an article on apple dev forums
https://devforums.apple.com/message/128046 (dev account required)
Which says it was a change in iOS 3.1 but a "workaround" is
use UIWebView to open the tel: url, after the call, your app will relaunch, but you get the annoying do you want to make this call alert.
I have't verified this works as described, just thought I'd point it out
From iOS 5, use below...
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"12345678"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Just use telprompt:// instead of tel://
telprompt will prompt the user first, and when call ends,it will go back to your application.
NSString *myNumber = [#"telprompt://" stringByAppendingString:txtMobileNo.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myNumber]];
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.
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).
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.