如何通过phonegap打开iPhone应用程序

发布于 2024-12-11 08:43:15 字数 168 浏览 0 评论 0原文

我想从我的phonegap应用程序中打开联系人和日历等iPhone应用程序,我不介意这样做会将我的应用程序置于后台。我可以打开浏览器并使用 window.open 但如何打开其他应用程序?

例如 window.open("contacts://", '_blank'); 不起作用

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

源来凯始玺欢你 2024-12-18 08:43:15

一个应用程序(基于 PhoneGap 或其他方式)可以导致另一个应用程序启动的唯一方法是打开使用目标应用程序的自定义 URL 方案的 URL。因此,如果联系人应用程序支持某些自定义方案,那么您很幸运。如果没有,那你就不走运了。

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.

勿忘初心 2024-12-18 08:43:15

您将需要编写一个自定义phonegap插件,以便您可以访问您在objective C中编写的自定义方法。

官方phonegap文档是此处
我将简要解释您将如何执行此操作。
在您的 javascript 中,您将调用以下代码:

 PhoneGap.exec("OpenMailAppPlugin.openMailApp",parameter1);

在 Objective C 中,您将创建一个新文件 OpenMailAppPlugin 类。阅读上面的链接以获取确切的说明,但重要的方法是这样的。

-(void) openMailApp:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options {
            NSString *parameter1 = [paramArray objectAtIndex:0]; //recieves information from javascript function

           NSURL* mailURL = [NSURL URLWithString: @"mailto:%@[email protected]&subject=Greetings%20from%Cupertino!&body=Wish%20you%20were%20here!",paramter1];
      [[UIApplication sharedApplication] openURL: mailURL];
 }

此外,您可能有兴趣将信息发回到您的phonegap 应用程序。您可以通过注入发送参数的 javascript 调用来完成此操作。在你的 Objective C 函数中你会做这样的事情。

 NSString * jsCallBack = [NSString stringWithFormat:@"myJavascriptFunction('%@');",parameter];    
        [self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];

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:%@[email protected]&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];
枫林﹌晚霞¤ 2024-12-18 08:43:15

正如前面所回答的,使用 URL 方案是可行的。如果您有多个应用程序并且希望能够从另一个应用程序中打开一个,那么使用 PhoneGap 构建时非常简单:您只需要 将 URL 方案添加到您的 config.xml 文件,例如:

// In config.xml
<gap:url-scheme>
    <scheme>app1scheme</scheme>
</gap:url-scheme>

然后从您的其他应用程序中您将获得一个指向 app1scheme://,例如简单地

<a href="app1scheme://">Start App1</a>

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>
一花一树开 2024-12-18 08:43:15

以下是所有 iOS/iPhone 应用程序 url 的列表

  1. 视频 - 视频:
  2. 音乐 - 音乐:
  3. Youtube - youtube.com
  4. iTunes 商店 - itms:
  5. iBooks - itms-books:
  6. App Store - itms-apps:
  7. 邮件发送 - mailto:
  8. 电话 -电话:

更多内容可以在这个过时的链接中找到
http://www.wiki.akosma.com/IPhone_URL_Schemes

看看这个如何实现你的网址
https://appurl.org/docs-handling-android

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

阳光①夏 2024-12-18 08:43:15

需要使用插件,不幸的是你需要本机ios代码:

这个有效:
https://github.com/phonegap/phonegap-plugins/tree/master /iOS/ExternalFileUtil

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文