uni-app app 跳转 微信小程序(安卓/ios)

867 阅读1分钟

uni-app app 跳转 微信小程序(安卓/ios)

近日接到需求,需要实现在 app 中直接跳转到微信小程序中,其实非常简单,uni-app 都已经集成好了。 安卓和ios 有点区别,这个需要注意一下,在下面的代码中有体现 。

		// #ifdef APP-PLUS
		// 如果是ios 需要先login 然后在 执行下面的代码 isIOS 这个方法根据你项目中的来定义 即可
		if (isIOS()) {
			uni.login({
				provider: 'weixin',
				success: function(loginRes1) {
						plus.share.getServices(function(res) {
						var sweixin = null;
						for (var i = 0; i < res.length; i++) {
							var t = res[i];
							if (t.id == 'weixin') {
								sweixin = t;
							}
						}
				
						if (sweixin) {
							sweixin.launchMiniProgram({
								id: '小程序原始id',
								path: '路径 可以带 参数',
								type: 0
							});
						}
					}, function(res) {
						console.log(JSON.stringify(res));
					});
				}
			});
		} else {
			plus.share.getServices(function(res) {
				var sweixin = null;
				for (var i = 0; i < res.length; i++) {
					var t = res[i];
					if (t.id == 'weixin') {
						sweixin = t;
					}
				}
		
				if (sweixin) {
					sweixin.launchMiniProgram({
						id: '小程序原始id',
						path: '路径 可以带 参数',
						type: 0
					});
				}
			}, function(res) {
				console.log(JSON.stringify(res));
			});
		}
		//#endif