how do I open iphone apps via phonegap

2019-02-10 23:45发布

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

5条回答
该账号已被封号
2楼-- · 2019-02-11 00:19

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];
查看更多
虎瘦雄心在
3楼-- · 2019-02-11 00:20

Need to use a plugin, unfortunately you need native ios code:

This one works: https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ExternalFileUtil

查看更多
神经病院院长
4楼-- · 2019-02-11 00:23

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

<a href="app1scheme://">Start App1</a>
查看更多
Emotional °昔
5楼-- · 2019-02-11 00:39

Here is the list of all the iOS/iPhone app url

  1. Video - video:
  2. Music - music:
  3. Youtube - youtube.com
  4. iTunes store - itms:
  5. iBooks - itms-books:
  6. App Store - itms-apps:
  7. Mail sending - mailto:
  8. 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

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-02-11 00:41

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.

查看更多
登录 后发表回答