How can I open up just the iTunes app. Not any subpages in the app like a song or video but just the app. Right now I am using: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://music"]]; but sometimes this gives an error saying invalid hostname: music. When I use [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://"]]; I get bad URL.
I have tested the following and it seems to be working fine
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://?action=music"]];
Related
I am working on a map application in my iPhone app.
I have a button go.
When the user clicks this button in this method I want to check if user has installed the waze application on his iphone. If yes then navigate to waze application otherwise open iPhone's default map app.
Try to do this way :
NSString *wazeAppURL = #"waze://";
NSString *mapsAppURL = #"maps://";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:wazeAppURL]];
NSString *url = canOpenURL ? wazeAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Here, canOpenURL allows you to test if the Waze app is installed on your iPhone. if iPhone can open the url waze:// it means you already have the app and it will launch it. Otherwise it will launch the default Maps app. Safari won't be called.
To open an app you need to call
BOOL canOpenURL = [[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:#"app://"]];
if ( canOpenUrl ) [[UIApplication sharedApplication]
openURL:[NSURL URLWithString:url]];
To find all the url, go to this page: http://handleopenurl.com/
For waze in particular, http://handleopenurl.com/scheme/waze
hope this helps.
Note that on iOS you can also navigate to Google Maps -- and pass along the query string or geopoint. Here's one example of navigating to a specific geopoint:
if (self.mapView.userLocation.location) {
NSString *urlAsString = [NSString stringWithFormat:#"comgooglemaps://?q=%f,%f", self.mapView.userLocation.location.coordinate.latitude, self.mapView.userLocation.location.coordinate.longitude];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlAsString]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlAsString]];
}
}
Just a suggestion to enhance the user experience.
I am making an app for a charity and Apple's review guidelines state that all donations must be made outside of the app in Safari, except for SMS donations, which we're not doing anyway. How do I make a button, that when tapped, goes to a specific URL in Safari? Thanks for your help!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"your.website.here"]];
And put it in an IBAction for your button.
There might be a problem connecting to your site try this:
NSURL *url = [NSURLWithString:#"your.website.here"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(#"%#%#",#"Failed to open url:",[url description]);
They actually have a post on it here:
How can I launch Safari from an iPhone app?
You can use this code in button click event
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"your url"]];
it automatically opens in safari
I need to call a number +91 (number),but if i use tel:// url it does not make a call from a iphone app.
How to call a number coming in any format.
The iphone will dial a number using either of the formats listed below.
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"tel://15415551234"]];
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"tel:15415551234"]];
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"tel:1-541-555-1234"]];
Link for Apple documentation on the tel: url scheme
I am in this situation where I have to display a button which says "Open myApp" (if myApp is installed on the device) or it says "Download myApp" (if myApp is not installed on the device) in an iphone app. To do this, I need to detect whether an app (with a known custom URL) has been installed on the device. How can I do this? Thanks in advance.
UPDATED 8th January 2014 - 3 things you can do
I actually had to do this for a client again. They wanted users to be able to open their second app from the main app if it had been installed.
This is my finding. Use the canOpenURL method to check if an app is installed or/and then use the openURL method to
Open the application installed on the iOS device
Take the user to the app store directly pointing them to the app/your list of developer apps
Take them to a website instead
All code samples available for each scenario
//Find out if the application has been installed on the iOS device
- (BOOL)isMyAppInstalled {
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"nameOfMyApp:"]];
}
- (IBAction)openOrDownloadApp {
//This will return true if the app is installed on the iOS device
if ([self myAppIsInstalled]){
//Opens the application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"nameOfMyApp:"]];
}
else { //App is not installed so do one of following:
//1. Take the user to the apple store so they can download the app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/nameOfMyApp"]];
//OR
//2. Take the user to a list of applications from a developer
//or company exclude all punctuation and space characters.
//for example 'Pavan's Apps'
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/PavansApps"]];
//OR
//3. Take your users to a website instead, with maybe instructions/information
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.pavan.com/WhyTheHellDidTheAppNotOpen_what_now.html"]];
}
}
Choose one option, I've just spoiled you with choice. Choose one that fits your requirements.
In my case I had to use all three options in different areas of the program.
If the URL scheme for your app is "myapp:", then
BOOL myAppInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"myapp:"]];
(Requires iOS 3.0.)
To check app is install in device or not
1) In info.plist add LSApplicationQueriesSchemes as below example
2) and in URL Types
3) Now to check app is install or not
- (IBAction)openAppPressed:(UIButton *)sender {
NSString *urlString = #"XYZAPP://";
NSURL *url = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itunes link for download app"]];
}
}
You can add a simple meta tag in the head of any page that needs this app-sniffing.
For more info, go here:
http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html
For those using canOpenURL it is always safe to migrate from this to openURL:options:completionHandler:
NSString *urlString = #"XYZAPP://";
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url options:#{} completionHandler:^(BOOL success) {
if (!success) {
[[UIApplication sharedApplication] openURL:appStoreUrl options:#{} completionHandler:nil];
}
}];
because that doesn't require you to declare the scheme ahead of time.
canOpenURL which is deprecated already has some odd limitations because Twitter used it to detect hundreds of apps long ago.
i am working on an application in which i needs to call safari when i click on a button.....
please tell me how to do this
should i create a new view for this ?
kindly help....
please also tell about importing messagebox and callmanager if possible.....
(not talking about sending msg or call from my app ...know that is not possible... i want to call inbuilt applications only) .
also wanto confirm that will my app close when i will call these inbuilt applications....
thanks....
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://9016098909891"]];
You can use the above function to call from the iphone
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
USe this to open safari and so on.. hope yo got the idea what exactly to do....
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms://9016098909891"]];
uSe the above to send SMS from iphone
hAPPY cODING....
If you call openURL with a general (for example not a youtube link) web page, then by default it will be opened through safari. However, your app will be terminated.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.yahoo.com"]];
Sorry, can't help about the messagebox.