小程序收货地址报错chooseAddress:fail the api need to be declared in the requiredPrivateInfos field inapp.json

项目场景:

        最近做的小程序商城项目获取微信小程序收货地址接口wx.chooseAddress时,返回errMsg为: "chooseAddress:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json"


原因分析:

这是由于微信官方做了优化,自 2022 年 7 月 14 日后发布的小程序,若使用该接口,需要在 app.json 中进行声明,否则将无法正常使用该接口,2022年7月14日前发布的小程序不受影响。详情请看小程序官方公告:地理位置接口新增与相关流程调整


解决方案:

一、uni-app项目

打开小程序项目配置文件,src/manifest.json文件,注意插入代码位置。代码中还有其它配置项,可以多试一下,我的仅添加一个便解决了,注意配置完保存后要重新运行一下项目。

代码如下:

    "mp-weixin": { /* 微信小程序特有相关 */

        "appid": "",

        "setting": {

            "urlCheck": false

        },

        "usingComponents": true,

        "requiredPrivateInfos": [

             //"getFuzzyLocation",
             //"choosePoi",

            "chooseAddress"

        ]

    },

二、原生小程序

详情见官方文档:原生小程序更新后收获地址官方配置文档

1、需配置的接口列表:

2、配置规则

在 app.json 中 requiredPrivateInfos 配置项中声明,代码如下:

"requiredPrivateInfos":[
    "getFuzzyLocation",
    "choosePoi",
    "chooseAddress"
    ],

猜你喜欢

转载自blog.csdn.net/CSDN_xiaoyuan/article/details/126562097