简体   繁体   English

如何从链接启动我的Android / IOS应用

[英]How to launch my Android / IOS app from a link

I have made android/IOS application using PHONEGAP BUILD its working fine for mi. 我已经使用PHONEGAP BUILD使android / IOS应用程序对mi正常工作。 Now i want to open that Application through link. 现在,我想通过链接打开该应用程序。 So that I can provide this link to customers through mail and messages so they can directly open application by clicking on link. 这样我就可以通过邮件和消息向客户提供此链接,以便他们可以通过单击链接直接打开应用程序。 For this what changes i have to do in my config file. 为此,我必须在配置文件中进行哪些更改。 And how to make that link to open a application? 以及如何使该链接打开应用程序? please help mi out. 请帮忙。

For iOS, you must go to YourApp-Info.plist, go to (or create if you don't have it yet) "URL types" Array -> Add one item with the following fields: 1) URL identifier - String - "your app identifier" 2) URL Schemes - Array 2.1) Item 0 - String - "yourApp" 对于iOS,您必须转到YourApp-Info.plist,转到(或创建(如果尚未创建的话))“ URL类型”数组->添加具有以下字段的一项:1)URL标识符-字符串-“您的应用程序标识符“ 2)URL方案-数组2.1)项目0-字符串-” yourApp“

The link you send must match the URL Scheme, like so : "yourApp://whatever". 您发送的链接必须与URL方案匹配,例如:“ yourApp:// whatever”。 By doing the above steps, the iOS will register your app to be one of the apps to respond to the "yourApp" URL scheme, just like facebook responds to "fb://" 通过执行上述步骤,iOS将把您的应用注册为响应“ yourApp” URL方案的应用之一,就像facebook响应“ fb://”一样

You can find more information here: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/ 您可以在此处找到更多信息: http : //mobile.tutsplus.com/tutorials/iphone/ios-sdk-working-with-url-schemes/

Once your app has been opened from an URL scheme, you can continue with the development in your AppDelegate.m in 通过URL方案打开应用后,您可以在AppDelegate.m中继续进行开发。

 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

if (url) {
    NSString *urlScheme = [url scheme];
    if (urlScheme != nil && [urlScheme isEqualToString:@"yourApp"]) {

        NSString *path = [NSString stringWithString:url.path];
        NSString *urlHost = [NSString stringWithString:url.host];
    ....

Here you can parse the rest of your URL, in order to bring the user to different screens or any other action. 在这里,您可以解析URL的其余部分,以使用户进入不同的屏幕或执行任何其他操作。

You will need to register a Custom URL Scheme in your config.xml. 您将需要在config.xml中注册自定义URL方案。 This is currently only supported by iOS apps on PhoneGap Build. 当前仅在PhoneGap Build上的iOS应用支持此功能。 From the PGB docs : 从PGB文档

iOS Only. 仅限iOS。 Allows registration of custom URL schemes. 允许注册自定义URL方案。

 <gap:url-scheme name="com.acme.myscheme" role="None"> <scheme>pgbr</scheme> <scheme>pgbw</scheme> </gap:url-scheme> 
  • Multiple gap:url-scheme elements can be present. 可以存在多个gap:url-scheme元素。
  • name, optional, defaults to the application bundle id. 名称(可选),默认为应用程序捆绑包ID。 This has to be unique. 这必须是唯一的。 If a duplicate is found the build will fail. 如果发现重复,则构建将失败。
  • role must be Editor, Viewer, Shell or None, optional, defaults to None. 角色必须是Editor,Viewer,Shell或None,可选,默认为None。
  • at least one scheme must be present. 至少必须存在一个方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM