Expo 应用
一个通用库,在运行时提供有关原生应用的 ID、应用名称和构建版本的信息。
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
expo-application 提供有关本地应用的 ID、应用名称和运行时构建版本的有用信息。
安装
🌐 Installation
- npx expo install expo-applicationIf you are installing this in an existing React Native app, make sure to install expo in your project.
应用接口
🌐 API
import * as Application from 'expo-application';
Constants
Type: string | null
The ID of the application. On Android, this is the application ID. On iOS, this is the bundle ID.
On web, this is null.
Example
"com.cocoacasts.scribbles", "com.apple.Pages"
Type: string | null
The human-readable name of the application that is displayed with the app's icon on the device's
home screen or desktop. On Android and iOS, this value is a string unless the name could not be
retrieved, in which case this value will be null. On web this value is null.
Example
"Expo", "Yelp", "Instagram"
Type: string | null
The human-readable version of the native application that may be displayed in the app store.
At time when native app is built, on Android, this is the version name set by version
in app config, and on iOS, the Info.plist value for CFBundleShortVersionString.
On web, this value is null.
Example
"2.11.0"
Type: string | null
The internal build version of the native application that the app stores may use to distinguish
between different binaries. At the time when native app is built, On Android, this is the version
code set by android.versionCode in app config, and on iOS, the Info.plist value for
CFBundleVersion (set with ios.buildNumber value in app config in a standalone app).
On web, this value is null. The return type on Android and iOS is string.
Example
"114"
Methods
Gets the value of Settings.Secure.ANDROID_ID.
This is a hexadecimal string unique to each combination of app-signing key, user, and device.
The value may change if a factory reset is performed on the device or if an APK signing key changes.
For more information about how the platform handles ANDROID_ID in Android 8.0 (API level 26)
and higher, see Android 8.0 Behavior Changes.
On iOS and web, this function is unavailable.
In versions of the platform lower than Android 8.0 (API level 26), this value remains constant for the lifetime of the user's device. See the ANDROID_ID official docs for more information.
stringExample
Application.getAndroidId(); // "dd96dec43fb81c97"
Gets the time the app was installed onto the device, not counting subsequent updates. If the app is uninstalled and reinstalled, this method returns the time the app was reinstalled.
- On Android, this method uses
PackageInfo.firstInstallTime. - On iOS, this method uses the
NSFileCreationDateof the app's document root directory. - On web, this method returns
null.
A Promise that fulfills with a Date object that specifies the time the app
was installed on the device.
Example
await Application.getInstallationTimeAsync(); // 2019-07-18T18:08:26.121Z
Gets the referrer URL of the installed app with the Install Referrer API
from the Google Play Store. In practice, the referrer URL may not be a complete, absolute URL.
Promise<string>A Promise that fulfills with a string of the referrer URL of the installed app.
Example
await Application.getInstallReferrerAsync(); // "utm_source=google-play&utm_medium=organic"
Gets the iOS application release type.
Promise<ApplicationReleaseType>A Promise which fulfills with an ApplicationReleaseType.
Gets the iOS "identifier for vendor" (IDFV)
value, a string ID that uniquely identifies a device to the app’s vendor. This method may
sometimes return nil, in which case wait and call the method again later. This might happen
when the device has been restarted before the user has unlocked the device.
The OS will change the vendor identifier if all apps from the current app's vendor have been uninstalled.
Promise<string | null>A Promise that fulfills with a string specifying the app's vendor ID. Apps from the
same vendor will return the same ID. See Apple's documentation for more information about the
vendor ID's semantics.
Example
await Application.getIosIdForVendorAsync(); // "68753A44-4D6F-1226-9C60-0050E4C00067"
Gets the current Apple Push Notification (APN) service environment.
A Promise that fulfills with the string, either 'development' or 'production',
based on the current APN environment, or null on the simulator as it does not support registering with APNs.
Types
Literal Type: union
Maps to the aps-environment key in the native target's registered entitlements.
Acceptable values are: 'development' | 'production' | null
Enums
错误代码
🌐 Error codes
| 代码 | 描述 |
|---|---|
ERR_APPLICATION_PACKAGE_NAME_NOT_FOUND | 由 getInstallationTimeAsync 和 getLastUpdateTimeAsync 抛出的错误代码。如果无法获取包信息或包名称,可能会抛出此错误。 |
ERR_APPLICATION_INSTALL_REFERRER_UNAVAILABLE | 当前的 Play 商店应用不提供安装引用者 API,或者可能未安装 Play 商店。当在没有预装 Play 商店的 AVD 上进行测试时,例如 Google Pixel 3 和 Nexus 6,可能会出现此错误代码。 |
ERR_APPLICATION_INSTALL_REFERRER_CONNECTION | 无法建立与 Google Play 商店的连接。 |
ERR_APPLICATION_INSTALL_REFERRER_REMOTE_EXCEPTION | 在与 Play 商店建立连接后抛出了 RemoteException。如果托管远程对象的进程不再可用,通常意味着该进程崩溃,这种情况可能会发生。有关更多信息,请参见 关于 RemoteException 的这个 StackOverflow 答案。 |
ERR_APPLICATION_INSTALL_REFERRER | getInstallReferrerAsync 方法的一般默认情况错误代码。如果在获取安装推荐者时发生异常,但异常不是更具体的错误,将抛出此错误代码。该错误将随 responseCode 一起提供。 |
ERR_APPLICATION_INSTALL_REFERRER_SERVICE_DISCONNECTED | 与安装推荐服务的连接丢失。当尝试连接并设置安装推荐服务时,如果连接丢失,就会抛出此错误。更多信息请参见Android 文档。 |