ios打开浏览器plus.runtime.openURL无效

调用第三方程序打开指定的URL:

plus.runtime.openURL( url, errorCB, identity );

参数:
url: ( String ) 必选 要打开的URL地址
字符串类型,各平台支持的地址类型存在差异,参考平台URL支持表。

errorCB: ( OpenErrorCallback ) 可选,打开URL地址失败的回调
打开指定URL地址失败时回调,并返回失败信息。

identity: ( String ) 可选 指定打开URL地址的程序名称
在iOS平台此参数被忽略,在Android平台为程序包名,如果指定的包名不存在,则打开URL地址失败。

plus.runtime.openURL(appInfo.app_open_url, function (res) {
     console.log('openURL', JSON.stringify(res))
})

打印结果:

{"code":-1,"message":"无效的参数"}

ios中地址要求规范,需要转码使用encodeURI()处理一下地址,问题解决

plus.runtime.openURL(encodeURI(appInfo.app_open_url), function (res) {
     console.log('openURL', JSON.stringify(res))
})

另附:Andriod设备跳转第三方应用市场下载软件

mui.plusReady(function () {
       if (plus.os.name === 'Android') {
            let Uri = plus.android.importClass('android.net.Uri')
            let uri = Uri.parse(`market://details?id=com.baidu.BaiduMap`) //id换成自己所需要的
            let Intent = plus.android.importClass('android.content.Intent')
            let intent = new Intent(Intent.ACTION_VIEW, uri)
            let main = plus.android.runtimeMainActivity()
            main.startActivity(intent)
       }
})

猜你喜欢

转载自blog.csdn.net/m0_53149377/article/details/131287230