手机拍照上传图片闪退
发布于 7 年前 作者 xiayao 6852 次浏览 来自 问答

在体验者版本,用真机实测的时候,部分机型(就是许多手机是可以正常执行的,以下代码也在编译器里运行正常)在拍照上传图片的时候会出现闪退的问题,请问有什么官方解决方案么?

测试手机:iphone6 微信版本6.5.18

代码如下:这是小程序一个页面的代码有两个拍照上传的区域,第一次的拍照上传不会有闪退,第二次的会直接闪退,两次都是拍照,不是相册。后来同一套代码,第二次的如果改成相册选图就不会闪退。

chooseImg(e){

    var that = this;

    if (that.data.companyDisabled === ‘yes’){

        that.setData({

            alertLoadInf: ‘状态为审核中或审核通过时,不可修改’,  //模拟弹出框

            showAlert: true

        })

    return; //阻止修改

    }

    console.log(e)

    var imgTag = e.currentTarget.dataset.img;

    

    wx.chooseImage({

    count: 1,

    sizeType: [‘compressed’],

    sourceType: [‘album’, ‘camera’],

    success: function (res) {

    // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片

    var tempFilePaths = res.tempFilePaths

    var isSuccess = false;

 

    if (imgTag == 1){

    var sortId = ‘A0007’

    }else{

    var sortId = ‘A0008’

    }

    

    wx.showLoading({

        mask:true,

        title: ‘图片上传中’,

    })

        wx.uploadFile({ //上传图片 法人身份证相关

            url: url + ‘/mediainfo/upLoadtoPic?sortId=’ + sortId + ‘&businessKey=&relationId=&relationIdType=CUST_ID&type=’,

            filePath: tempFilePaths[0],

            name: ‘FILES’,

            header: {

            ‘cookie’: ‘jsid=’ + wx.getStorageSync(‘session’),

            ‘request’: ‘wechat’,

            ‘content-type’: ‘application/json’

            },

            success: function (res) {

            

                console.log(res)

                if(JSON.parse(res.data).httpCode === 200){

                    wx.showToast({

                        title: ‘上传成功’,

                        duration:800

                    })

                isSuccess = true;

                } else if (JSON.parse(res.data).httpCode === 314) {

                console.log(‘登录失效’)

                    wx.showToast({

                        title: ‘登录失效,请重登’,

                        mask: true,

                        duration: 1000,

                        icon: ‘loading’

                    })

                

                setTimeout(function () {

                    wx.navigateBack({

                        delta: 1

                    })

                }, 1000)

                

                var pages = getCurrentPages();

                    pages[0].setData({

                        redirectPage: “login”

                    })

                return;

                }else{

                wx.showToast({

                    title: ‘上传失败’,

                    duration: 800,

                    icon:‘loading’

                })

                }

    

            },

            fail:function(){

                wx.showToast({

                    title: ‘上传失败’,

                    duration: 800,

                    icon: ‘loading’

                })

            },

            complete:function(){

                // wx.hideLoading()

                    if(isSuccess){

                    that.setData({

                        [‘img’ + imgTag]: tempFilePaths[0]

                    })

                        console.log(that.data[‘img’ + imgTag])

                    }

            }

        })

      

        }

    })

}

4 回复

木有,这个应该需要微信团队优化吧

兄弟,解决没有呀

为什么小程序微信官方直播就可以呀,这个只是传个图片都不可以

今年上半年就有的问题 当时我用iphone6plus拍照上传闪退 6s不会闪退 就没管它了 谁知道最近接了个项目 老板的手机是iphone6plus 总是问我这个闪退怎么回事。。。。

回到顶部