Acefzp
Acefzp
  • 发布:2025-06-05 14:51
  • 更新:2025-06-05 16:49
  • 阅读:118

uniapp iOS端调用跳转微信小程序没反应

分类:uni-app

我在开发uniapp 唤起微信小程序的时候安卓可以正常唤起并打开,但是iOS却没有任何反应,直接到sweixin.launchMiniProgram这个方法,没有正确和错误信息的回调,而且也没有任何报错提示。

            handlePayment(productData) {  
                // #ifdef APP-PLUS  
                try {  
                    const platform = uni.getSystemInfoSync().platform.toLowerCase();  
                    uni.getProvider({  
                        service: 'oauth',  
                        success: (res) => {  
                            if (res.provider.indexOf('weixin') === -1) {  
                                return uni.showToast({  
                                    title: '请先安装微信',  
                                    icon: 'none'  
                                });  
                            }  
                            plus.share.getServices((services) => {  
                                let sweixin = null;  
                                for (let i = 0; i < services.length; i++) {  
                                    if (services[i].id == 'weixin') {  
                                        sweixin = services[i];  
                                    }  
                                }  
                                if (sweixin) {  
                                    try {  
                                        var aiCodeData = {  
                                            inviteNo: '11',  
                                            pointCode: '22',  
                                            product_flag: ''  
                                        };  
                                        const path =  
                                            ``;  
                                        if (!sweixin || !sweixin.nativeClient) {  
                                            uni.showToast({  
                                                title: '微信服务未初始化',  
                                                icon: 'none',  
                                            });  
                                            return;  
                                        }  
                                        const miniProgramParams = {  
                                            id: '',  
                                            path: ``,  
                                            type: 0  
                                        };  
                                        try {  
                                            sweixin.launchMiniProgram(miniProgramParams,  
                                                function(success) {  
                                                    console.log('launchMiniProgram成功:', success);  
                                                    uni.showToast({  
                                                        title: '跳转成功',  
                                                        icon: 'success'  
                                                    });  
                                                },  
                                                function(err) {  
                                                    console.log('launchMiniProgram失败:', err);  
                                                    uni.showToast({  
                                                        title: '跳转失败:' + (err.message ||  
                                                            '未知错误'),  
                                                        icon: 'none'  
                                                    });  
                                                });  
                                        } catch (e) {  
                                            console.log('跳转过程出现异常:', e);  
                                            uni.showToast({  
                                                title: '跳转异常,请稍后重试',  
                                                icon: 'none'  
                                            });  
                                        }  
                                    } catch (e) {  
                                        console.log('处理跳转数据时出错:', e);  
                                        uni.showToast({  
                                            title: '处理跳转数据时出错',  
                                            icon: 'none',  
                                        });  
                                    }  
                                } else {  
                                    console.log('未找到微信服务');  
                                    uni.showToast({  
                                        title: '未找到微信服务',  
                                        icon: 'none',  
                                    });  
                                }  
                            }, (err) => {  
                                console.log('获取服务失败:', err);  
                                uni.showToast({  
                                    title: '获取微信服务失败',  
                                    icon: 'none',  
                                });  
                            });  
                        },  
                        fail: (err) => {  
                            console.log('获取服务供应商失败:', err);  
                            uni.showToast({  
                                title: '微信登录初始化失败',  
                                icon: 'none'  
                            });  
                        }  
                    });  
                } catch (e) {  
                    console.log('执行过程中出错:', e);  
                    uni.showToast({  
                        title: '执行过程中出错',  
                        icon: 'none',  
                    });  
                }  
                // #endif  
            }
2025-06-05 14:51 负责人:无 分享
已邀请:
蔡cai

蔡cai - 开发的插件:https://ask.dcloud.net.cn/article/41539

manifest.json--->App模块配置--->Share模块--->IOS平台通用链接对吗

  • 蔡cai

    https://uniapp.dcloud.net.cn/api/plugins/universal-links.html这里面都有配置是嘛

    2025-06-05 15:28

  • Acefzp (作者)

    是对的,和微信开放平台保持一致的

    2025-06-05 15:28

  • 蔡cai

    回复 Acefzp: 那就不清楚了

    2025-06-05 15:33

  • Acefzp (作者)

    回复 蔡cai: 嗯呢,谢谢回复。很奇怪,iOS调用微信分享都能成功调起来,证明通用链接没问题。就是这个打开微信小程序方法,死活没有任何回调和报错,也调不起来。

    2025-06-05 15:37

  • 蔡cai

    回复 Acefzp: 那你查下吧,看看有没有和你类似的情况

    2025-06-05 15:40

Backspace

Backspace

miniProgramParams里面参数怎么写的?

  • Acefzp (作者)

    id是 微信小程序的原始id gh_开头的,然后path不写正常是唤起小程序首页,type:0,

    2025-06-05 16:06

  • Backspace

    回复 Acefzp: ios 版本是多少的 iphone16是可以跳转的

    2025-06-05 16:19

  • Acefzp (作者)

    回复 Backspace: 16.7.11

    2025-06-05 16:40

Backspace

Backspace

// #ifdef APP-PLUS  
plus.share.getServices(  
    function (s: any) {  
        let sweixin: any = null  
        for (let i = 0; i < s.length; i++) {  
            if (s[i].id == 'weixin') {  
                sweixin = s[i]  
            }  
        }  
        //判断是否有微信  
        if (sweixin) {  
            //唤起微信跳转小程序  
            // https://www.html5plus.org/doc/zh_cn/share.html#plus.share.WeixinMiniProgramOptions  
            sweixin.launchMiniProgram(  
                {  
                    id: 'xxxx',  
                    type: 0,  
                    path: `xxxx`,  
                },  
                (res) => {  
                    console.log(res)  
                },  
                (err) => {  
                    console.log('微信唤起失败', err)  
                },  
            )  
        } else {  
            uni.showToast({  
                title: '微信唤起失败,请检查是否有微信应用',  
                icon: 'none',  
                duration: 2000,  
            })  
        }  
    },  
    function (e) {  
        console.log('微信唤起失败', e)  
    },  
)  
// #endif

试试这样写

  • Acefzp (作者)

    还是就走到sweixin.launchMiniProgram这个方法就没任何反应了,没有任何报错信息和日志输出。

    2025-06-05 17:09

  • Backspace

    回复 Acefzp: 有没有可能只能打包之后才能跳呢

    2025-06-05 17:17

  • Backspace

    回复 Acefzp: 我们开发的app 也涉及到了跳转小程序需求 跳转是没问题的

    2025-06-05 17:24

  • Acefzp (作者)

    回复 Backspace: 好的,我再看看,目前线上的也没办法跳转了。

    2025-06-06 09:57

要回复问题请先登录注册