Not Able to launch Google Maps App from inside another app - iphone

I am trying to open Google Maps App from inside an iOS App.
I am using this code:
[[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
but its not working. Can anyone tell me whats the issue?

First of all canOpenURL won't open an app. It just checks that the app can open the app or not. Use openURL method instead.
if([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]])
{
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:#"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
}
Note:
For opening a third party app using the URL Scheme. It should be installed on the device.
canOpenURL:
Returns whether an application can open a given URL resource.
- (BOOL)canOpenURL:(NSURL *)url
Parameters
url
A URL object that identifies a given resource. The URL’s scheme—possibly a custom scheme—identifies which application can
handle the URL.
Return Value
NO if no application is available that will accept the URL; otherwise,
returns YES.
Discussion
This method guarantees that that if openURL: is called, another
application will be launched to handle it. It does not guarantee that
the full URL is valid.
openURL:
Opens the resource at the specified URL.
- (BOOL)openURL:(NSURL *)url
Parameters
url
An object representing a URL (Universal Resource Locator). UIKit supports the http:, https:, tel:, and mailto: schemes.
Return Value
YES if the resource located by the URL was successfully opened;
otherwise NO.
Discussion
The URL can locate a resource in the same or other application. If the
resource is another application, invoking this method may cause the
calling application to quit so the other one can be launched.
You may call canOpenURL: before calling this one to verify that there
is an application that can handle it.
Please refer UIApplication Class.

Related

Problems open AppStore programmatically

I'm having problems opening the app store (to suggest an app update).
This is what i'm doing:
NSURL *url = [NSURL URLWithString:#"macappstore://itunes.apple.com/app/id[my_id]?mt=12"];
if ([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
}
canOpenURL is returning false, also i tried without the conditional but it doesn't work.
In addition i tried to use NSWorkspace instead the openURL method in UIApplication but i'm having compilation errors, surely this are dependencies issues but i couldn't find Cocoa.framework and neither AppKit.framework to add one of them to the binaryLibraries of my project.
For iOS, you should be using the prefix itms-apps:// instead of macappstore://. This will link you directly to the App Store app, instead of through a Safari redirect (as http:// or https:// will do).
Lots more on this topic covered here:
How to link to apps on the app store

Make an autocall programmatically in iOS

Is it possible to do a call to a predefinite number in iphone sdk with some system api?
You can do this as follows, but the user will need to accept the call placement.
NSURL *telephoneURL = [NSURL URLWithString:#"tel:01234567890"];
[[UIApplication sharedApplication] openURL:telephoneURL];
If you're attempting to place a call without the user's acknowledgement, then this (thankfully) isn't possible using the public API.

Help me to run a iPhone application

I am going to develop a iPhone application.
In that i need to run another iPhone app when the user clicks on the button.
Is it possible to run a iPhone app from another iPhone app?
If possible, Please let me know your inputs on this.
Thanks for any help.
[copy and paste of a previous answer I gave here for the click-averse]
You can use the url scheme built into iOS. For example, you could call Safari with a url because it is registered as the application which handles the http URL scheme
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com/"]]
The openURL: method is an instance method of the singleton UIApplication instance, on which you can call any application installed which registers in its plist an ability to handle some sort of input data.
Here's a list of common url schemes in iOS.
A little known way to detect the existence of another application on a device is to use canOpenURL: on the same singleton instance:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"cydia://"]])
{
NSLog(#"cydia installed");
}
else
{
NSLog(#"cydia not installed");
}
Only if that other app is already installed and run and has been designed to register a custom URL handler to itself with the OS.
The your app can run it by using that custom URL scheme.
If the app has a custom URL Schema and you know what it is, then it is possible to launch another app form yours.
When user pressed the button, your current app will close and run the new app..
Yea.. Its possible.. BUT you must know the "short link" of the other app.. I tried it before and even successfully transferred data from the lite version to the full version..
Its called url scheme..
Here's a link:
http://www.idev101.com/code/Objective-C/custom_url_schemes.html
Hope it can achieve what you want..

Direct "rate in iTunes" link in my app?

I've seen posts here on Stackoverflow that describe how to allow users to be directed to apps on the app store.
Is there a way to link directly to the rating and comments form in the App Store?
This IS possible using the technique described on this blog:
http://www.memention.com/blog/2009/09/03/Open-Reviews.html
basically you call UIApplication openURL with the following:
NSString* url = [NSString stringWithFormat: #"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%#", myAppID];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
To get your app ID before your app is available in the app store, use iTunesConnect to define your new app - give it a name, description, icon, screenshots, etc. Once defined, you can get the Apple ID from the Identifiers section for the app.
EDIT:
Here is a secondary url/method that works:
NSString* url = [NSString stringWithFormat: #"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%#&pageNumber=0&sortOrdering=1&type=Purple+Software&mt=8", appid];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url ]];
I believe the difference between the two is that the first technique (itms-apps://) will launch the App Store app directly while the second one (http://) will launch it indirectly via a redirect resulting from the http web URL. This would have to be confirmed; this is only my recollection.
Answers here are outdated.
This works on my end (Xcode 5 - iOS 7 - works only on Device, not simulator!):
itms-apps://itunes.apple.com/app/idYOUR_APP_ID
For versions lower than iOS 7 use the old one:
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=YOUR_APP_ID
Simple method that I am using is;
-(void)rateApp {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[#"itms-apps://itunes.apple.com/app/" stringByAppendingString: #"id547101139"]]]; }
You can also use SKStoreProductViewController as an alternative. It will open the store in your app. You may like it better than opening another app, especially on iPads.
Thanks to Ahment swift version:
UIApplication.sharedApplication().openURL(NSURL(string: "itms-apps://itunes.apple.com/app/id951334398")!)

Launching application from a SMS message

I am new to iphone application development.
I have a sample application that needs to be launched from a SMS message. I have no idea on how to do this. Please help me.
Note that if SMS operates in the same manner as Mail on the iPhone, you'll need to enclose your custom URL in brackets to make it launch the application responding to that scheme. For example,
<yourapp://yoururl>
will work, but
yourapp://yoururl
will not.
Allow your application to respond to some url (eg: myapp://launch ) and include the url in the SMS, when the user launches that URL your application will launch.
I'm sure that is not the most straight forward way (since the SMS needs to include your custom URL) but I don't know if it is possible with any arbitrary SMS to launch an arbitrary applciation
do a google on iphone URL scheme and you will find lots of detail on how to implement this
here is an example
the below appdelegate method tells the full url that used to open your app
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//you could parse the url and take action according to that
}
The below app delegate method tells which app caused to open your app
- (BOOL)application:(UIApplication *)application openURL: (NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
//you could capture the refered app custom url and open back from your app
return YES;
}
with following code snippet you could open the app that opened your app
NSURL *urlObj = [NSURL URLWithString:url];
[[UIApplication sharedApplication] openURL:urlObj];
Pass the custom app url.
It works fine. thanks hhafez!
I composed a SMS with url format "myapp://". It didn't work. Then I tried "", then it worked. thanks Brad!