如何在cordova/phonegap应用程序中提供和处理深层链接

Ryu*_*yuk 10 android android-activity cordova cordova-plugins

嗨我想知道一个Cordova/Phonegap插件或在我的Sencha Touch/Cordova应用程序中公开和处理深层链接的方式

到目前为止,我能够深入链接到其他应用程序,让我们说打开Goog​​le Play到特定的应用程序详细信息页面.

使用此插件https://github.com/code4jhon/org.apache.cordova.startapp

所以我想做的是让其他应用程序在我的应用程序中打开特定的视图或功能.我想支持Android和IOS.

那么底线是否有一个Cordova插件,可以在IOS上展示Android及其对手的活动?

或者如何实现这一目标?

查看Cordova文档,但没有找到任何帮助,doc链接将非常感激.

men*_*tat 11

您可以尝试https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin

它对我来说很完美.

记得在安装后清理/构建

您可以处理变量实现handleOpenURL

function handleOpenURL(url) {
  console.log("received url: " + url);
}
Run Code Online (Sandbox Code Playgroud)


小智 5

我能够使用 Branch Metrics 完成此操作。他们是一家新的创业公司,非常棒。

在此处查看他们的cordova插件文档以获取深层链接:

https://github.com/BranchMetrics/Branch-PhoneGap-Cordova-SDK#initialize-sdk-and-register-deep-link-routing-function

我建议阅读他们所有的文档以了解该怎么做。但是,使用 Ionicframework 和 AngularJS,我构建了一个可以在您的应用程序中使用的服务:

https://gist.github.com/sean-hill/627fa40f96577baae378

使用 Branch 的插件构建项目后,请按照以下步骤进行 iOS 和 Android 配置。

IOS

将此添加到您的.plist文件中:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>yourappname</string>
        </array>
    </dict>
</array>
Run Code Online (Sandbox Code Playgroud)

然后cordova build ios; cordova emulate ios。要检查它是否正常工作,请打开您的模拟器,转到 Safari 并输入yourappname://并查看它是否重定向到您的应用程序。

安卓

AndroidManifest.xml构建android后将其添加到您的文件中:

<intent-filter>
    <data android:scheme="yourappname" android:host="open" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

将此添加到您的config.xml文件中:

<preference name="AndroidLaunchMode" value="singleTask" />
Run Code Online (Sandbox Code Playgroud)

然后再次构建,你应该在通往伟大的深层链接成功的路上!

根据@Deminetix 请求,这就是我关闭分支会话的方式。

document.addEventListener("pause", function(){
    var branch = window.Branch;
    branch.closeSession();  
}, false);
Run Code Online (Sandbox Code Playgroud)

玩得开心编码:)


MPa*_*ulo 5

有一个新的插件可以处理Android和iOS的通用链接:https://github.com/nordnet/cordova-universal-links-plugin