一个通用库,在运行时提供原生应用的 ID、应用名称和构建版本信息。
expo-application
提供有关原生应用本身的有用信息,例如 ID、应用名称和构建版本。
¥expo-application
provides useful information about the native application, itself, such as the ID, app name, and build version.
¥Installation
-
npx expo install expo-application
If you are installing this in an existing React Native app (bare workflow), start by installing expo
in your project. Then, follow the additional instructions as mentioned by library's README under "Installation in bare React Native projects" section.
import * as Application from 'expo-application';
Application.applicationId
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"
Application.applicationName
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"
Application.nativeApplicationVersion
Type: string | null
The human-readable version of the native application that may be displayed in the app store.
This is the Info.plist
value for CFBundleShortVersionString
on iOS and the version name set
by version
in app.json
on Android at the time the native app was built.
On web, this value is null
.
Example
"2.11.0"
Application.nativeBuildVersion
Type: string | null
The internal build version of the native application that the app store may use to distinguish
between different binaries. This is the Info.plist
value for CFBundleVersion
on iOS (set with
ios.buildNumber
value in app.json
in a standalone app) and the version code set by
android.versionCode
in app.json
on Android at the time the native app was built. On web, this
value is null
. The return type on Android and iOS is string
.
Example
Android: "114"
, iOS: "2.11.0"
Application.getAndroidId()
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.
string
Example
"dd96dec43fb81c97"
Application.getInstallReferrerAsync()
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"
Application.getInstallationTimeAsync()
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.
NSFileCreationDate
of the app's document root directory.PackageInfo.firstInstallTime
.null
.Returns 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
Application.getIosApplicationReleaseTypeAsync()
Gets the iOS application release type.
Returns a promise which fulfills with an ApplicationReleaseType
.
Application.getIosIdForVendorAsync()
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"
Application.getIosPushNotificationServiceEnvironmentAsync()
Gets the current Apple Push Notification (APN) service environment.
Returns a promise fulfilled 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.
Application.getLastUpdateTimeAsync()
Gets the last time the app was updated from the Google Play Store.
Returns a Promise
that fulfills with a Date
object that specifies the last time
the app was updated via the Google Play Store).
Example
await Application.getLastUpdateTimeAsync();
// 2019-07-18T21:20:16.887Z
PushNotificationServiceEnvironment
Literal Type: multiple types
Maps to the aps-environment
key in the native target's registered entitlements.
Acceptable values are: 'development'
| 'production'
| null
ApplicationReleaseType
ApplicationReleaseType Values
UNKNOWN
ApplicationReleaseType.UNKNOWN = 0
SIMULATOR
ApplicationReleaseType.SIMULATOR = 1
ENTERPRISE
ApplicationReleaseType.ENTERPRISE = 2
DEVELOPMENT
ApplicationReleaseType.DEVELOPMENT = 3
AD_HOC
ApplicationReleaseType.AD_HOC = 4
APP_STORE
ApplicationReleaseType.APP_STORE = 5
¥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 。如果托管远程对象的进程不再可用,则可能会发生这种情况,这通常意味着进程崩溃。参见 https://stackoverflow.com/questions/3156389/android-remoteexceptions-and-services。 |
ERR_APPLICATION_INSTALL_REFERRER | getInstallReferrerAsync 方法的一般默认情况错误代码。如果获取安装引荐来源网址时发生异常,则会抛出此错误代码,但该异常不是更精确的错误。responseCode 与错误一起提供。 |
ERR_APPLICATION_INSTALL_REFERRER_SERVICE_DISCONNECTED | 与安装引荐来源网址服务的连接丢失。当尝试连接并设置安装引荐来源网址服务但连接丢失时,会引发此错误。请参阅 安卓文档 了解更多信息。 |