Android 上的 Ionic InAppBrowser 无法导航到自定义 URL 方案

2024-04-14移动开发问题
11

本文介绍了Android 上的 Ionic InAppBrowser 无法导航到自定义 URL 方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个设置,我在插件 InAppBrowser 中打开一个带有目标_blank"的 url.插件 Deeplinks 也已安装和配置.

I am having a setup, where I open a url in the plugin InAppBrowser with target '_blank'. The plugin Deeplinks is also installed and configured.

const browser: InAppBrowserObject = this.iab.create(url, '_blank', <InAppBrowserOptions>{
    location: "no",
    toolbar: "no",
    footer: "no"
});

browser.on('loadstart').subscribe((event: InAppBrowserEvent) => {
    console.log(event);

    if (event.url.indexOf('wflwr://payment/success') > -1) {
        browser.close();
    }

    if (event.url.indexOf('wflwr://payment/cancel') > -1) {
        browser.close();
    }

    if (event.url.indexOf('wflwr://payment/error') > -1) {
        browser.close();
    }
});

我将其缩短以仅显示重要部分.打开的网址是https://www.voan.ch/wfl/(它是在真正实现之前只是一个 Mock)

I shortened it to show just the important parts. The url which is opened is https://www.voan.ch/wfl/ (it is just a Mock before the real implementation)

预期的行为是,单击 url 上的每个链接时,应用程序内的浏览器实例应该关闭.这在 iOS 上按预期工作,但在 Android 上却不行.事件只是没有被触发.如果我将其中一个网址更改为例如<a href="https://www.google.com">CANCEL</a>,然后触发事件.

The expected behaviour is, that on a click on each of the links on the url, the browser instance inside the app should close. This works as intended on iOS, but not on Android. The event is just not triggered. If I change one of the urls to e.g. <a href="https://www.google.com">CANCEL</a>, then the Event gets triggered.

推荐答案

在最新的 pr

要使用它,您需要两件事:

to use it you will need 2 things:

例如允许 whatsapp 自定义方案和 twitter

for example to allow whatsapp custom scheme and twitter

  • 使用您想要支持的自定义方案添加新的 config.xml 首选项:<代码><preference name="AllowedSchemes" value="whatsapp,twitter"/>`
  • 添加事件监听器customscheme:<代码>inAppBrowserRef.addEventListener('customscheme', function (event) {//在这里做任何你想做的事情:window.open(event.url, "_system");});

这篇关于Android 上的 Ionic InAppBrowser 无法导航到自定义 URL 方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何在 COCOS2d Android 中使用 CClistview?
How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)...
2024-08-12 移动开发问题
5

cocos2d-android:如何显示分数
cocos2d-android: how to display score(cocos2d-android:如何显示分数)...
2024-08-11 移动开发问题
7

Sqlite 数据库未从资产文件夹 Android 复制
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)...
2024-04-15 移动开发问题
8

SQLite 数据库副本在由设备而不是模拟器生成时出现损坏
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)...
2024-04-15 移动开发问题
4

安卓文件拷贝
Android file copy(安卓文件拷贝)...
2024-04-15 移动开发问题
6

Android如何在android中检测Edittext的Copy事件
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)...
2024-04-15 移动开发问题
5