0

我正在尝试将 Progressive Web Apps 添加到我的服务器。我不希望为每个应用程序创建一个新网站。我的偏好是将每个应用程序添加到这样的网站的子域中:www.example.com/app1

问题是当我在这里运行语句列表生成器时: https ://developers.google.com/digital-asset-links/tools/generator

仅当我将assetlinks.json 放在此处时才有效:www.example.com。如果是这种情况,那么我在 www.example.com 中只能拥有一个应用程序。我尝试将assetlinks.json 放在这里 1) www.example.com/app1 2) www.example.com/app1/.well-known 和 3) www.example.com 。唯一有效的是#3。

还向 androidmanifest.xml 添加了以下意图过滤器,但这不起作用:

<intent-filter android:label="@string/app_name" android:autoVerify="true" >
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>
            <!-- Edit android:host to handle links to the target URL-->
            <data android:scheme="https"
                android:host="example.com"
                android:pathPrefix="/app1" />
</intent-filter>

我不敢相信您必须为每个渐进式网络应用程序提供不同的网站。有什么建议么?

4

1 回答 1

1

这是可能的。例如,假设您正在开发 2 个应用程序:

而且,由于这些应用程序将是不同的 TWA,这也意味着您将为每个应用程序拥有不同的包名称:

assetslinks.json 文件应该在https://example.com/.well-known/assetlinks.json上可用,并且应该列出两个应用程序:

[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target" : { "namespace": "android_app", "package_name": "com.example.app1",
                 "sha256_cert_fingerprints": ["<APP_1_FINGERPRINT>"] }
  }, 
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target" : { "namespace": "android_app", "package_name": "com.example.app2",
                 "sha256_cert_fingerprints": ["<APP_2_FINGERPRINT>"] }
  }

]

每个应用程序都有自己的asset_statements 声明,将应用程序链接到授权来源:

[{ "relation": ["delegate_permission/common.handle_all_urls"],
   "target": {"namespace": "web", "site": "https://example.com"}}]

有几点需要注意:

  1. 如果应用程序 1 将打开https://example.com/app1。但是,如果用户导航到https://example.com/app2,他们将保持全屏显示。导航到 /app1 的应用程序 2 也是如此。
  2. 应用程序 1 可以启动打开https://example.com/app2的 TWA ,反之亦然。因此,如果您不信任所有 PWA 和相应的应用程序,则不建议使用此方法。

如果上述两项中的任何一项存在问题,则使用子域将是更好的解决方案。

于 2019-05-23T19:37:58.200 回答