# wx.getLaunchOptionsSync

获取小游戏冷启动时的参数。热启动参数通过 wx.onShowwx.getEnterOptionsSync 接口获取。

# 返回值

属性 类型 说明
scene number 启动小游戏的场景值
query Object 启动小游戏的 query 参数
shareTicket string shareTicket
referrerInfo Object 来源信息
userLocation Object 用户地区信息(出海新增,可能为 null)

# 获取用户所在地区信息

出海版本在国内返回值基础上新增了 userLocation 字段,可获取用户所在地区用于判断是否出隐私政策弹窗。

# 示例

const launchOptions = wx.getLaunchOptionsSync()
if (launchOptions.userLocation) {
  const { countryId, country, province, city } = launchOptions.userLocation
  // { countryId: "CN", country: "中国", province: "香港", city: "未知" }
  console.log('国家代码:', countryId)
  console.log('国家:', country)
  console.log('省份:', province)
  console.log('城市:', city)
}

# userLocation 结构

属性 类型 说明
countryId string 国家/地区代码,如 "CN""US"
country string 国家/地区名称,如 "中国"
province string 省份/州名称
city string 城市名称

userLocation 对象本身及其字段不一定存在,取决于客户端可获取的信息。