uni

您所在的位置:网站首页 uniapp跳转外部页面 uni

uni

2023-08-15 06:33| 来源: 网络整理| 查看: 265

已经安装跳转应用的情况 1.对于IOS配置打包

配置路径manifest->app-plus->distribute->ios

注意不要使用大写及中文以及特殊字符等,示例代码如下 "urltypes" : [ { "urlidentifier" : "com.runtest.test", "urlschemes" : [ "runtest" ] } ]

配置好后需要打包后才能生效,在另一个应用或者程序中访问带有唤起链接的页面访问runtest://

如下

点击链接后会提示是否打开

2.安卓配置打包

云打包:配置路径manifest->app-plus->distribute->android 配置与ios类似,示例代码如下  

"schemes" : "runtest"

配置好后云打包,与ios相同

本地离线打包

打开Android项目的AndroidManifest.xml文件。将应用入口activity中的android:scheme值改为需要的UrlSchemes即可。 若未知是否安装应用 在唤起应用页面用js代码请求该协议,如果在500ms内,如果有应用程序能解析这个协议,那么就能打开该应用;如果超过500ms就跳转到app下载页。

// 打开链接

openApp() {                 var ua = window.navigator.userAgent.toLowerCase();                 if (ua.match(/MicroMessenger/i) == 'micromessenger') {                     uni.showModal({                         showCancel: false,                         title: "提示",                         content: "请用外部浏览器打开!"                     })                     return                 }                 if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {                     window.location = "https://apps.apple.com/us/app/商店链接" // 可以在苹果开发者中心找对应APP的链接                     // window.location = "runtest://"                 } else if (navigator.userAgent.match(/android/i)) {

                        window.location.href = "runtest://page=index"                         uni.showLoading({                             mask: true                         })

                        uni.hideLoading();                         uni.showModal({                             title: "提示",                             content: "暂未检测到客户端,是否下载?",                             success: function(res) {                                 if (res.confirm) {                                     window.location =                                         "下载链接"                                 } else if (res.cancel) {                                     // window.close();                                 }                             }                         })                 }             },

因为在打开APP过程中有添加Loading状态去先校验是否有安装此APP,如果存在这个APP打开后,该页面应取消LOADING状态并且禁止弹出未安装提示:

onHide() {             if (this.downLoadHandle) {                 uni.hideLoading()                 clearTimeout(this.downLoadHandle)             }         },

在应用中对于从外部唤起的链接可以根据参数对应跳转指定页面,由于IOS的部分问题,需要包一个定时器才会生效 onShow: function() { // #ifdef APP-PLUS let urlMap={ index:"/pages/index/index" } setTimeout(function() { var args = plus.runtime.arguments.split("://page=")[1]; util.toast(urlMap[args]) if (args) { plus.runtime.arguments = ''; uni.navigateTo({ url: urlMap[args] || "/pages/index/index" }) } }, 10); // #endif }   可参考dcloud官方文档:

Android:https://ask.dcloud.net.cn/article/409

iOS:https://ask.dcloud.net.cn/article/64



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3