首页 > 解决方案 > App-link 将打开应用程序但会调用回调

问题描述

我正在使用 Angular Nativescript 构建一个 android 应用程序。我希望应用程序能够通过链接打开。我在我的 AndroidManifest.xml 中添加了这个:

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="https"
                    android:host="www.myApp.com"
                    android:pathPrefix="/springView"/>
</intent-filter>

在我的 app.comonent.ts 中:

import { Component, NgZone, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { registerUniversalLinkCallback } from "@nativescript-community/universal-links";

@Component({
    selector: "ns-app",
    templateUrl: "./app.component.html"
})
export class AppComponent implements OnInit {
    constructor(private router: Router,
        private zone: NgZone) { }

    ngOnInit() {
        registerUniversalLinkCallback(url => {
            this.zone.run(() => {
                alert("Got here!");
                
            })
        })
    }
}

当应用程序在后台并且我单击链接时,它会转到那里,但是如果应用程序关闭,链接会打开它,但不会转到回调函数

标签: javascriptandroidangularnativescript

解决方案


推荐阅读