如何在 Cordova 应用程序中添加包含内容的通用链接

问题描述

我是在 Android 上制作的。

  1. 在 Android Studio 的 MainActivity.java 中添加新活动

    // 在 config.xml 中设置 loadUrl(launchUrl);

改为

 // Set by <content src="index.html" /> in config.xml
        loadUrl("file:///android_asset/www/Any_Page.html);
  1. 使用任意名称保存新活动

  2. 在Android studio的上层菜单-工具-应用链接助手-打开url映射编辑器添加带有新活动的URL映射路径 所以不需要任何插件。 现在链接应用中打开的内容

但我无法在 Xcode 中为 iOS 应用程序创建相同的链接。 在 Appdelegate.m 中,我可以更改起始页**

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    self.viewController = [[MainViewController alloc] init];
    self.viewController.startPage = @«My_page.html; // relative path works
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end

但是我需要获取 url 路径才能在 Cordova 中选择我的起始页。 还有第二种方法 - 在 index.html 中从 JavaScript 更改起始页

<script>
window.location.href = “MyPage.html”;
</script>

但我需要我的应用程序打开的 url 路径。 我网站上的 URL 路径与应用中的相同。

/content/page1.html
/content/page2.html

等等... 我需要从链接打开我的应用时 - 在应用中显示相同的内容

解决方法

Cordova 中有一个未维护的通用链接插件。

不久前我创建了一个分支并进行了一些修复:https://github.com/GEDYSIntraWare/cordova-universal-links-plugin