I want to open iphone apps like Contacts and Calendar from within my phonegap app, I don't mind that doing so will put my app in the background. I can open the browser and using window.open but how do I open other apps?
eg window.open("contacts://", '_blank'); doesn't work
The only way that one app, PhoneGap-based or otherwise, can cause another app to launch is to open an URL that uses the target app's custom URL scheme. So, if the Contacts app supports some custom scheme, you're in luck. If not, you're out of luck.
You are going to need to write a custom phonegap plugin so that you can access custom methods you write in objective C.
The official phonegap documentation is here.
I'll briefly explain how you will do this.
In your javascript you will call this code :
PhoneGap.exec("OpenMailAppPlugin.openMailApp",parameter1);
In objective C you will create a new file OpenMailAppPlugin class. Read the link above for exact instuctions, but the important method will be soemthing like this.
-(void) openMailApp:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options {
NSString *parameter1 = [paramArray objectAtIndex:0]; //recieves information from javascript function
NSURL* mailURL = [NSURL URLWithString: #"mailto:%#?cc=bar#example.com&subject=Greetings%20from%Cupertino!&body=Wish%20you%20were%20here!",paramter1];
[[UIApplication sharedApplication] openURL: mailURL];
}
additionally, you may be interested in sending information back to your phonegap application. You can do this by injecting a javascript call that sends parameters. In your objective C function you would do something like this.
NSString * jsCallBack = [NSString stringWithFormat:#"myJavascriptFunction('%#');",parameter];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
As previously answered, using a URL scheme can work. If you have several apps and you want to be able to open one from the other, then it's really simple when using PhoneGap build: you just need to add the URL scheme to your config.xml file, eg:
// In config.xml
<gap:url-scheme>
<scheme>app1scheme</scheme>
</gap:url-scheme>
Then from your other app you'll just have a link to app1scheme://, eg simply
Start App1
Here is the list of all the iOS/iPhone app url
Video - video:
Music - music:
Youtube - youtube.com
iTunes store - itms:
iBooks - itms-books:
App Store - itms-apps:
Mail sending - mailto:
Telephone - tel:
More can be found at this outdated link
http://www.wiki.akosma.com/IPhone_URL_Schemes
Look at this on how you can implement your's url
https://appurl.org/docs-handling-android
Need to use a plugin, unfortunately you need native ios code:
This one works:
https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ExternalFileUtil
Related
There are apps in the iOS app store that let you send encrypted messages via sms and it seems like they are using NSURL to create a clickable link that opens their app automatically (from the iMessage app) with the "hidden message" already showing in the app.
My question is, how does one store information within an NSURL? I figured out who to launch my app from another app using NSURL but how can you store extra information for the launched app to use such as text, an image, or a link to an online video?
I apologize if this is a basic question, I haven't had to work with URLs much. Many thanks.
We can achieve communication between apps through the URL Schemes concept.
if you can go through this link below, you will get some idea on how to share data between the applications
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/
When you register an URL scheme in your application's info.plist like myapp you can use the following url's to invoke your application.
myapp://
myapp://some/path/here
myapp://?foo=1&bar=2
myapp://some/path/here?foo=1&bar=2
And you can check the received url's in the
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
method of app delegate and do the action according to each url.
Reference : Launching application via custom url scheme
The data is not stored in NSURL. However, you can pass parameters along with the URL and accordingly retrieve them in the new opened app.
Now you can use these params in the way you want.
Im opening a map like this:
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%#,%#", destLat, destLong];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
Is there any way to choose with which app will open the map? For example, Safari, or the maps app, or Tom Tom app...
Yes, you should use one of the iPhone URL schemes. There is a pretty hefty list available here.
Note that you should first check if the application you want to launch is available before using a certain URL scheme.
If Tom Tom exposes some url scheme you can try that one. Otherwise the default url scheme handlers are "hard coded" to the system and you can't override / change them i.e. "http:" will be always opened by Safari except for "maps.google.com" domains, etc.
It looks like Twitter registers the URI scheme of twitter://, but after playing around with it I can't get it to directly open a user's profile. I've tried:
twitter://username
twitter://user/username
twitter://profile/username
with no luck. I'll need it to work on Android as well.
Thoughts?
I found two URL schemes for twitter tweetie:// and twitter://:
tweetie:///user?screen_name=jessicaalba
twitter:///user?screen_name=jessicaalba
On this wiki site you can find a lot of other iphone url schemes (including twitter)
Doesn't seem to be official documented anywhere so I wouldn't count on all versions of the Twitter app supporting it but http://groups.google.com/group/twitter-development-talk/browse_thread/thread/92b958b7af002993?pli=1 gives a hint that might be worth a try:
I just found that "twitter:///user?screen_name=tvdw" works as well.
I know you are looking specifically to open it up with the official Twitter app but what if the person doesn't have the app, then the functionality will not work in your app.
Why not just use MGTwitterEngine in this case since it will work for everyone and it will remain in your app?
For those wondering how to test if the scheme executes:
- (BOOL)openURL:(NSString *)url
- (void) clickTwitter {
if (![self openURL:#"twitter:///user?screen_name=mufumbo"]) {
if (![self openURL:#"tweetie:///user?screen_name=mufumbo"]) {
[self openURL:#"http://twitter.com/mufumbo"];
}
}
}
you can include many more and make it a generic loop.
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..
I am developing an application in which I need to find the apps - such as Skype, Facebook - which are already installed on the iPhone device.
I need to check it Objective-C. Please give me a code snippet if possible; otherwise a link to the solution.
If it not possible then tell me another way to check installed application on iPhone device.
Thanks in advance.
If the app you're checking for has a URI scheme registered, you can probe for that and assume the app is installed. Have a look at -(BOOL)canOpenURL:(NSURL *)url, try something along the lines of
if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]] )
{
NSLog(#"will open facebook urls");
}
However, this does not give the guarantee that the genuine facebook app will respond to fb://
if ([[NSFileManager defaultManager] fileExistsAtPath:#"/Applications/Cydia.app"])