菜鸟一枚2号
菜鸟一枚2号
  • 发布:2020-11-19 18:53
  • 更新:2023-03-22 16:34
  • 阅读:1314

uni.shareWithSystem打包后无法弹出原生分享框

分类:uni-app

uni.shareWithSystem打包后无法弹出原生分享框,自定义基座却可以正常运行。代码如下:

uni.shareWithSystem({  
    type: 'image',  
    imageUrl: '../../static/share.png',  
    success: function() {  
    },  
    fail: function() {  
                uni.showToast({title: "分享失败"});       
    }  
});

没有错误信息,不知道什么原因,难以调试。
请问需要什么额外配置吗,我这里没有设置分享配置。
环境:
小米:Remi6A
系统版本:MIUI11.0.5.5|稳定版

2020-11-19 18:53 负责人:无 分享
已邀请:
菜鸟一枚2号

菜鸟一枚2号 (作者) - uniapp扩展好难,提问也好难,邮箱不给验证按钮,我怎么验证

<template>  
    <view class="content">  
        <image class="logo" :src="img"></image>  
        <view class="text-area">  
            <text class="title">Hello</text>  
        </view>  
        <view style="padding: 5px;"><button type="default" @click="handleShareImg">分享</button></view>  
        <!-- ~@ -->  
    </view>  
</template>  

<script>  
export default {  
    data() {  
        return {  
            img: '../../static/img/share.png'  
        };  
    },  
    onLoad() {  
        uni.getImageInfo({  
            src: '../../static/img/share.png',  
            success(obj) {  
                this.img = obj.path;  
            }  
        });  
    },  
    methods: {  
        handleShareImg() {  
            uni.shareWithSystem({  
                type: 'image',  
                imageUrl: this.img,  
                success: function() {  
                    uni.showToast({ title: '分享成功' });  
                },  
                fail: function(e) {  
                    uni.showModal({  
                        title: '错误',  
                        content: JSON.stringify(e)  
                    });  
                }  
            });  
        },  
    }  
};  
</script>  

<style>  
.content {  
    display: flex;  
    flex-direction: column;  
    align-items: center;  
    justify-content: center;  
}  

.logo {  
    height: 200rpx;  
    width: 200rpx;  
    margin-top: 200rpx;  
    margin-left: auto;  
    margin-right: auto;  
    margin-bottom: 50rpx;  
}  

.text-area {  
    display: flex;  
    justify-content: center;  
}  

.title {  
    font-size: 36rpx;  
    color: #8f8f94;  
}  
</style>

通过uni.getImageInfo方法是可以获取到图片的本地地址的,初步排除原生系统分享功能 不能用 不是因为图片找不到的问题。能想到的就是 是不是有什么权限没有配置。到此小弟已经黔驴技穷了,望知道的小伙伴能给小弟指一条明路。

菜鸟一枚2号

菜鸟一枚2号 (作者) - uniapp扩展好难,提问也好难,邮箱不给验证按钮,我怎么验证

打包后返回错误日志为:shareWithSystem:fail。基座运行正常,很奇怪啊

菜鸟一枚2号

菜鸟一枚2号 (作者) - uniapp扩展好难,提问也好难,邮箱不给验证按钮,我怎么验证

经测试,只是分享文字的话没有问题,分享图片的话,应该是图片路径没找到才出的问题。图片路径试了6种写法,还是没用。分别试了:
1 ./static/img/share.png;
2 ../../static/img/share.png
3 /static/img/share.png'
4 ~@/static/img/share.png
5 @/static/img/share.png
6 static/img/share.png
其中自定义基座可以用的是3、5、6。打包后,没有一个路径写法是能用的。
开了两天的贴了,官方的人呢,麻烦出来解释下static路径下的文件,在打包成app后,应该怎么获取啊。

Mr_hu

Mr_hu

我也遇到相同问题

爬坑之路

爬坑之路 - 爱开发

Android端高版本无法分析私有路径的图片,只能分享来自相册的图片(使用 uni.chooseImage 选择图像时请设置为原图)

要回复问题请先登录注册