粉末的沉淀
粉末的沉淀
  • 发布:2021-03-05 13:56
  • 更新:2021-11-30 16:49
  • 阅读:1155

【报Bug】uniapp添加联系人功能失效

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 3.1.2

手机系统: Android

手机系统版本号: Android 10

手机厂商: 华为

手机机型: P30 Pro

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

App下载地址或H5⽹址: https://m3w.cn/uniapp

示例代码:
<template>  
    <view>  
        <page-head :title="title"></page-head>  
        <view class="uni-common-mt">  
            <view class="uni-list">  
                <view class="uni-list-cell">  
                    <view class="uni-list-cell-left">  
                        <view class="uni-label">名称</view>  
                    </view>  
                    <view class="uni-list-cell-db">  
                        <input class="uni-input" type="text" placeholder="请输入联系人名称" name="name" :value="name" @input="nameChange"></input>  
                    </view>  
                </view>  
                <view class="uni-list-cell">  
                    <view class="uni-list-cell-left">  
                        <view class="uni-label">手机号</view>  
                    </view>  
                    <view class="uni-list-cell-db">  
                        <input class="uni-input" type="text" placeholder="请输入联系人手机号" name="phone" :value="phone" @input="phoneChange"></input>  
                    </view>  
                </view>  
            </view>  
            <view class="uni-padding-wrap">  
                <view class="uni-btn-v">  
                    <button type="primary" class="btn-setstorage" @tap="add">添加联系人</button>  
                </view>  
            </view>  
        </view>  
    </view>  
</template>  
<script>  
    // #ifdef APP-PLUS  
    import permision from "@/common/permission.js"  
    // #endif  
    export default {  
        data() {  
            return {  
                title: 'addPhoneContact',  
                name: '',  
                phone: ''  
            }  
        },  
        methods: {  
            nameChange: function(e) {  
                this.name = e.detail.value  
            },  
            phoneChange: function(e) {  
                this.phone = e.detail.value  
            },  
            async add() {  
                // #ifdef APP-PLUS  
                let status = await this.checkPermission();  
                if (status !== 1) {  
                    return;  
                }  
                // #endif  

                uni.addPhoneContact({  
                    firstName: this.name,  
                    mobilePhoneNumber: this.phone,  
                    success: function() {  
                        uni.showModal({  
                            content: '已成功添加联系人!',  
                            showCancel: false  
                        })  
                    },  
                    fail: function() {  
                        uni.showModal({  
                            content: '添加联系人失败!',  
                            showCancel: false  
                        })  
                    }  
                });  
            }  
            // #ifdef APP-PLUS  
            ,  
            async checkPermission() {  
                let status = permision.isIOS ? await permision.requestIOS('contact') :  
                    await permision.requestAndroid('android.permission.WRITE_CONTACTS');  

                if (status === null || status === 1) {  
                    status = 1;  
                } else {  
                    uni.showModal({  
                        content: "需要联系人权限",  
                        confirmText: "设置",  
                        success: function(res) {  
                            if (res.confirm) {  
                                permision.gotoAppSetting();  
                            }  
                        }  
                    })  
                }  
                return status;  
            }  
            // #endif  
        }  
    }  
</script>  

<style>  
</style>

操作步骤:

安装hello uniapp的安卓版,点击“实例”-“接口”-“设备”-“添加手机联系人”,输入姓名和电话号码,点击“添加联系人”

预期结果:

联系人被保存到手机通讯录

实际结果:

提示成功添加,但实际通讯录里并没有该条记录。

bug描述:

官网安卓hello uniapp里的添加联系人功能无效,虽然提示添加成功,但实际通讯录里并没有记录。

2021-03-05 13:56 负责人:无 分享
已邀请:
DCloud_UNI_Anne

DCloud_UNI_Anne

是必现吗?其他设备是否正常?测试Android 10,HONOR Play4T ,未复现问题。

  • 粉末的沉淀 (作者)

    终于知道怎回事了,我的通讯录设置的只显示华为账号下的联系人,uniapp是把联系人存在手机里了,要设置为显示全部联系人才可以看到uniapp添加的联系人。

    2021-03-06 16:53

2***@qq.com

2***@qq.com

permission.js 这个包怎么找

该问题目前已经被锁定, 无法添加新回复