【问题标题】:Is There a Way To Put a PWA/TWA App in a Sub-Domain有没有办法将 PWA/TWA 应用程序放在子域中
【发布时间】:2019-05-23 16:40:43
【问题描述】:

我正在尝试将 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>

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

【问题讨论】:

    标签: progressive-web-apps trusted-web-activity


    【解决方案1】:

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

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

    assetlinks.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 可以启动 TWA 打开 https://example.com/app2,反之亦然。因此,如果您不信任所有 PWA 和相应的应用程序,则不建议使用此方法。

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

    【讨论】:

    • 非常感谢。没想到您可以在一个assetlinks.json 文件中放置多个TWA。
    猜你喜欢
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 2021-04-20
    相关资源
    最近更新 更多