我使用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>
然后运行cordova build ios; cordova emulate ios
。为了检查它是否工作正常,打开模拟器,进入Safari并输入yourappname://
,看看是否重定向到您的应用程序。
Android
在构建Android后,将以下内容添加到您的AndroidManifest.xml
文件中:
<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>
将以下代码添加到您的
config.xml
文件中:
<preference name="AndroidLaunchMode" value="singleTask" />
然后重新构建,你就可以成功实现深层链接!
根据@Deminetix的请求,这是我如何关闭Branch会话。
document.addEventListener("pause", function(){
var branch = window.Branch;
branch.closeSession();
}, false);
玩得开心,编程愉快 :)
function handleOpenURL(url) { console.log("received url: " + url); }
- Reign.85