uni.getLaunchOptionsSync()
获取首次启动时的参数。返回值与App.onLaunch的回调参数一致
getLaunchOptionsSync 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS |
| 4.0 | 4.41 | 3.91 | 4.11 | 4.61 |
返回值
| 类型 |
| OnLaunchOptions |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | | path | string | 是 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | 4.0 | 4.41 | 3.91 | 4.11 | 4.61 |
| 首次启动时的页面路径。返回值与App.onLaunch的回调参数一致
| | appScheme | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | x | x | 4.25 | 4.25 | 4.81 |
| 首次启动时的Scheme。返回值与App.onLaunch的回调参数一致
| | appLink | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | x | x | x | 4.25 | 4.81 |
| 首次启动时的appLink。返回值与App.onLaunch的回调参数一致
| | query | UTSJSONObject | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | 4.0 | 4.41 | √ | √ | 4.81 |
| 启动时的 query 参数
| | apiCategory | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 需要基础库: 2.20.0
API 类别
可选值: - 'default': 默认类别; - 'nativeFunctionalized': 原生功能化,视频号直播商品、商品橱窗等场景打开的小程序; - 'browseOnly': 仅浏览,朋友圈快照页等场景打开的小程序; - 'embedded': 内嵌,通过打开半屏小程序能力打开的小程序; - 'chatTool': 聊天工具,通过打开聊天工具能力打开的小程序;
| | 合法值 | 兼容性 | 描述 | | default | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | nativeFunctionalized | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | browseOnly | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | embedded | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | chatTool | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - |
| | forwardMaterials | any | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 打开的文件信息数组,只有从聊天素材场景打开(scene为1173)才会携带该参数
| | referrerInfo | OnLaunchOptionsReferrerInfo | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 来源信息。从另一个小程序、公众号或 App 进入小程序时返回。否则返回 {}。(参见后文注意)
| | 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | | appId | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 来源小程序、公众号或 App 的 appId
| | extraData | any | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 来源小程序传过来的数据,scene=1037或1038时支持
|
| | scene | number | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| | | chatType | number | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 从微信群聊/单聊打开小程序时,chatType 表示具体微信群聊/单聊类型
可选值: - 1: 微信联系人单聊; - 2: 企业微信联系人单聊; - 3: 普通微信群聊; - 4: 企业微信互通群聊;
| | 合法值 | 兼容性 | 描述 | | 1 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | 2 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | 3 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | 4 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - |
| | shareTicket | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| |
|
- 如果应用通过scheme或applink(通用链接)启动,可以通过本API获取相应参数。配置scheme或applink需在AndroidManifest.xml或info.plist中配置,打包后生效。如开发直达页面功能,一般在应用的onShow生命周期监听。详见
示例
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
扫码体验 示例源码如下,请查看 pre > code 标签中的内容
<template>
<page-head title="getLaunchOptionsSync"></page-head>
<view class="uni-padding-wrap">
<button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
<view class="uni-common-mt">
<text>应用本次启动路径:</text>
<text style="margin-top: 5px">{{ launchOptionsPath }}</text>
</view>
<view class="uni-common-mt">
<text>应用本次启动:</text>
<text style="margin-top: 5px">{{ launchOptionsString }}</text>
</view>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
checked: false,
homePagePath: 'pages/tabBar/component',
launchOptionsPath: '',
launchOptionsString: '',
testResult: false
}
},
onReady() {
this.compareOnLaunchRes()
},
methods: {
compareOnLaunchRes() {
const launchOptions = uni.getLaunchOptionsSync();
this.launchOptionsString = JSON.stringify(launchOptions, null, 2)
const app = getApp()
const appOnLaunch = app.globalData.launchOptions
const isPathSame = launchOptions.path == appOnLaunch.path
const isAppSchemeSame = launchOptions.appScheme == appOnLaunch.appScheme
const isAppLinkSame = launchOptions.appLink == appOnLaunch.appLink
this.testResult = isPathSame && isAppSchemeSame && isAppLinkSame
},
getLaunchOptionsSync() {
const launchOptions = uni.getLaunchOptionsSync()
this.launchOptionsPath = launchOptions.path
if (launchOptions.path == this.homePagePath) {
this.checked = true
}
}
},
}
</script>
参见
uni.getEnterOptionsSync()
获取本次启动时的参数。返回值与App.onShow的回调参数一致
uni.getEnterOptionsSync 和 uni.getLaunchOptionsSync 的区别,相当于应用的 onShow 和 onLaunch 的区别,详见应用生命周期
getEnterOptionsSync 兼容性
| Web | 微信小程序 | Android | iOS | HarmonyOS |
| 4.0 | 4.41 | 4.25 | 4.25 | 4.61 |
返回值
| 类型 |
| OnShowOptions |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | | path | string | 是 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | 4.0 | 4.41 | 4.25 | 4.25 | 4.61 |
| 本次启动时页面的路径
| | appScheme | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | x | x | 4.25 | 4.25 | 4.81 |
| 本次启动时的Scheme。返回值与App.onShow的回调参数一致
| | appLink | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | x | x | x | 4.25 | 4.81 |
| 本次启动时的appLink。返回值与App.onShow的回调参数一致
| | query | UTSJSONObject | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | 4.0 | 4.41 | √ | √ | 4.81 |
| 启动时的 query 参数
| | apiCategory | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 需要基础库: 2.20.0
API 类别
可选值: - 'default': 默认类别; - 'nativeFunctionalized': 原生功能化,视频号直播商品、商品橱窗等场景打开的小程序; - 'browseOnly': 仅浏览,朋友圈快照页等场景打开的小程序; - 'embedded': 内嵌,通过打开半屏小程序能力打开的小程序; - 'chatTool': 聊天工具,通过打开聊天工具能力打开的小程序;
| | 合法值 | 兼容性 | 描述 | | default | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | nativeFunctionalized | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | browseOnly | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | embedded | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | chatTool | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - |
| | forwardMaterials | any | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 打开的文件信息数组,只有从聊天素材场景打开(scene为1173)才会携带该参数
| | referrerInfo | OnShowOptionsReferrerInfo | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 来源信息。从另一个小程序、公众号或 App 进入小程序时返回。否则返回 {}。(参见后文注意)
| | 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | | appId | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 来源小程序、公众号或 App 的 appId
| | extraData | any | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 来源小程序传过来的数据,scene=1037或1038时支持
|
| | scene | number | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| | | chatType | number | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 从微信群聊/单聊打开小程序时,chatType 表示具体微信群聊/单聊类型
可选值: - 1: 微信联系人单聊; - 2: 企业微信联系人单聊; - 3: 普通微信群聊; - 4: 企业微信互通群聊;
| | 合法值 | 兼容性 | 描述 | | 1 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | 2 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | 3 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - | | 4 | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | - | - | - | - |
| - |
| | shareTicket | string | 否 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| |
|
- 如果应用通过scheme或applink(通用链接)启动或从后台激活到前台,可以通过本API获取相应参数。配置scheme或applink需在AndroidManifest.xml或info.plist中配置,打包后生效。如开发直达页面功能,一般在应用的onShow生命周期监听。详见
示例
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
扫码体验 示例源码如下,请查看 pre > code 标签中的内容
<template>
<page-head title="getEnterOptionsSync"></page-head>
<view class="uni-padding-wrap">
<view class="uni-common-mt">
<text>应用本次启动路径:</text>
<text style="margin-top: 5px">{{ enterOptionsString }}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
enterOptionsString: '',
testResult: false
}
},
onReady() {
const app = getApp()
const appOnShow = app.globalData.onShowOption
const onShowOption = uni.getEnterOptionsSync()
this.enterOptionsString = JSON.stringify(onShowOption, null, 2)
this.testResult = (onShowOption.path == appOnShow.path && onShowOption.appScheme == appOnShow.appScheme && onShowOption.appLink == appOnShow.appLink)
}
}
</script>
参见
通用类型
GeneralCallbackResult
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
| errMsg | string | 是 | - | |
Web
|
微信小程序
|
Android
|
iOS
|
HarmonyOS
| | - | 4.41 | - | - | - |
| 错误信息 |