ios uni-app UrlSchemes唤起app plus.runtime.arguments无法取到值

ios uni-app UrlSchemes唤起app plus.runtime.arguments无法取到值

开发环境 版本号 项目创建方式
Mac 15.5 HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Mac

HBuilderX类型:正式

HBuilderX版本号:4.75

手机系统:iOS

手机系统版本号:iOS 18

手机厂商:苹果

手机机型:iphone 14

页面类型:vue

vue版本:vue3

打包方式:云端

示例代码:

onShow: function () {
	const options = plus.runtime.arguments
	console.log('options', options)
}
<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="UTF-8">
	<title>打开App</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<style>
		body {
			font-family: -apple-system, BlinkMacSystemFont, sans-serif;
			text-align: center;
			padding: 80px 20px;
		}

		h2 {
			color: #333;
		}

		.btn {
			background: #007aff;
			color: white;
			padding: 14px 24px;
			border-radius: 8px;
			font-size: 16px;
			text-decoration: none;
			display: inline-block;
			margin-top: 20px;
		}

		.tip {
			margin-top: 30px;
			font-size: 14px;
			color: #888;
		}
	</style>
</head>

<body>
	<h2>正在打开App...</h2>
	<p>若没有自动跳转,请点击下方按钮手动打开或下载 App</p>
	<a class="btn" href="yijing://artGallery?id=206">手动打开 App</a>
	<div class="tip">还没有安装?请点击跳转到应用市场或官网下载</div>
	<script>
		(function () {
			const start = Date.now();
			window.location.href = 'yijing://artGallery?id=206';
		})();
	</script>
</body>

</html>

操作步骤:

从浏览器点击按钮跳转到app

预期结果:

iOS也能返回 yijing://artGallery?id=206

实际结果:

ios返回的是{"name":"","path":"","query":""}


更多关于ios uni-app UrlSchemes唤起app plus.runtime.arguments无法取到值的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

把pages.json里的condition去掉重新打包就OK了。。。

更多关于ios uni-app UrlSchemes唤起app plus.runtime.arguments无法取到值的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在iOS环境下,plus.runtime.arguments 获取UrlSchemes参数确实存在兼容性问题。建议改用以下方案:

  1. onLaunch 生命周期中监听应用启动参数:
onLaunch: function(options) {
    console.log('App Launch:', options);
    if(options && options.path) {
        // 处理UrlSchemes参数
        this.handleUrlScheme(options);
    }
}
  1. 使用 plus.runtime.getProperty 获取启动参数:
onShow: function() {
    const args = plus.runtime.arguments;
    if(!args || args === '') {
        // iOS备用方案:尝试从应用属性获取
        plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
            console.log('widgetInfo:', widgetInfo);
        });
    } else {
        console.log('UrlScheme参数:', args);
    }
}
  1. 检查iOS配置,确保在manifest.json中正确声明UrlSchemes:
{
    "app-plus": {
        "distribute": {
            "apple": {
                "urlschemewhitelist": ["yijing"],
                "urltypes": [
                    {
                        "identifier": "com.yourcompany.yourapp",
                        "urlschemes": ["yijing"]
                    }
                ]
            }
        }
    }
}
回到顶部