解决小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos

897 阅读1分钟

image.png

unipp项目

打开uniapp项目的配置文件manifest.json,选择“源码视图”,找到mp-weixin在其下面加上“requiredPrivateInfos”节点

"mp-weixin": {
    "appid": "你的开发者id",
    "setting": {
            "urlCheck": true,
            "es6": true
    },
    "usingComponents": true,
    "permission": {
        "scope.userLocation": {
             "desc": "你的位置信息将用于小程序位置接口的效果展示"
        }
    },
    "requiredPrivateInfos": ["getLocation"]
},
原生小程序

打开项目的配置文件app.json,在其下面加上“requiredPrivateInfos”节点

{
    "pages": ["pages/index/index"],
    "permission": {
        "scope.userLocation": {
            "desc": "你的位置信息将用于小程序位置接口的效果展示"
        }
    },
    "requiredPrivateInfos": ["getLocation"]
}

官方文档 全局配置 | 微信开放文档 (qq.com)