1import { UnavailabilityError } from 'expo-modules-core'; 2 3import ExpoApplication from './ExpoApplication'; 4 5// @needsAudit 6/** 7 * The human-readable version of the native application that may be displayed in the app store. 8 * This is the `Info.plist` value for `CFBundleShortVersionString` on iOS and the version name set 9 * by `version` in `app.json` on Android at the time the native app was built. 10 * On web, this value is `null`. 11 * @example `"2.11.0"` 12 */ 13export const nativeApplicationVersion: string | null = ExpoApplication 14 ? ExpoApplication.nativeApplicationVersion || null 15 : null; 16 17// @needsAudit 18/** 19 * The internal build version of the native application that the app store may use to distinguish 20 * between different binaries. This is the `Info.plist` value for `CFBundleVersion` on iOS (set with 21 * `ios.buildNumber` value in `app.json` in a standalone app) and the version code set by 22 * `android.versionCode` in `app.json` on Android at the time the native app was built. On web, this 23 * value is `null`. The return type on Android and iOS is `string`. 24 * @example iOS: `"2.11.0"`, Android: `"114"` 25 */ 26export const nativeBuildVersion: string | null = ExpoApplication 27 ? ExpoApplication.nativeBuildVersion || null 28 : null; 29 30// @needsAudit 31/** 32 * The human-readable name of the application that is displayed with the app's icon on the device's 33 * home screen or desktop. On Android and iOS, this value is a `string` unless the name could not be 34 * retrieved, in which case this value will be `null`. On web this value is `null`. 35 * @example `"Expo"`, `"Yelp"`, `"Instagram"` 36 */ 37export const applicationName: string | null = ExpoApplication 38 ? ExpoApplication.applicationName || null 39 : null; 40 41// @needsAudit 42/** 43 * The ID of the application. On Android, this is the application ID. On iOS, this is the bundle ID. 44 * On web, this is `null`. 45 * @example `"com.cocoacasts.scribbles"`, `"com.apple.Pages"` 46 */ 47export const applicationId: string | null = ExpoApplication 48 ? ExpoApplication.applicationId || null 49 : null; 50 51// @needsAudit 52/** 53 * The value of [`Settings.Secure.ANDROID_ID`](https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID). 54 * This is a hexadecimal `string` unique to each combination of app-signing key, user, and device. 55 * The value may change if a factory reset is performed on the device or if an APK signing key changes. 56 * For more information about how the platform handles `ANDROID_ID` in Android 8.0 (API level 26) 57 * and higher, see [Android 8.0 Behavior Changes](https://developer.android.com/about/versions/oreo/android-8.0-changes.html#privacy-all). 58 * On iOS and web, this value is `null`. 59 * > In versions of the platform lower than Android 8.0 (API level 26), this value remains constant 60 * > for the lifetime of the user's device. See the [ANDROID_ID](https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID) 61 * > official docs for more information. 62 * @example `"dd96dec43fb81c97"` 63 * @platform android 64 */ 65export const androidId: string | null = ExpoApplication ? ExpoApplication.androidId || null : null; 66 67// @needsAudit 68/** 69 * Gets the referrer URL of the installed app with the [`Install Referrer API`](https://developer.android.com/google/play/installreferrer) 70 * from the Google Play Store. In practice, the referrer URL may not be a complete, absolute URL. 71 * @return A `Promise` that fulfills with a `string` of the referrer URL of the installed app. 72 * 73 * @example 74 * ```ts 75 * await Application.getInstallReferrerAsync(); 76 * // "utm_source=google-play&utm_medium=organic" 77 * ``` 78 * @platform android 79 */ 80export async function getInstallReferrerAsync(): Promise<string> { 81 if (!ExpoApplication.getInstallReferrerAsync) { 82 throw new UnavailabilityError('expo-application', 'getInstallReferrerAsync'); 83 } 84 return await ExpoApplication.getInstallReferrerAsync(); 85} 86 87// @needsAudit 88/** 89 * Gets the iOS "identifier for vendor" ([IDFV](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor)) 90 * value, a string ID that uniquely identifies a device to the app’s vendor. This method may 91 * sometimes return `nil`, in which case wait and call the method again later. This might happen 92 * when the device has been restarted before the user has unlocked the device. 93 * 94 * The OS will change the vendor identifier if all apps from the current app's vendor have been 95 * uninstalled. 96 * 97 * @return A `Promise` that fulfills with a `string` specifying the app's vendor ID. Apps from the 98 * same vendor will return the same ID. See Apple's documentation for more information about the 99 * vendor ID's semantics. 100 * 101 * @example 102 * ```ts 103 * await Application.getIosIdForVendorAsync(); 104 * // "68753A44-4D6F-1226-9C60-0050E4C00067" 105 * ``` 106 * @platform ios 107 */ 108export async function getIosIdForVendorAsync(): Promise<string | null> { 109 if (!ExpoApplication.getIosIdForVendorAsync) { 110 throw new UnavailabilityError('expo-application', 'getIosIdForVendorAsync'); 111 } 112 return (await ExpoApplication.getIosIdForVendorAsync()) ?? null; 113} 114 115// @docsMissing 116export enum ApplicationReleaseType { 117 UNKNOWN = 0, 118 SIMULATOR = 1, 119 ENTERPRISE = 2, 120 DEVELOPMENT = 3, 121 AD_HOC = 4, 122 APP_STORE = 5, 123} 124 125// @needsAudit 126/** 127 * Gets the iOS application release type. 128 * @return Returns a promise which fulfills with an [`ApplicationReleaseType`](#applicationreleasetype). 129 * @platform ios 130 */ 131export async function getIosApplicationReleaseTypeAsync(): Promise<ApplicationReleaseType> { 132 if (!ExpoApplication.getApplicationReleaseTypeAsync) { 133 throw new UnavailabilityError('expo-application', 'getApplicationReleaseTypeAsync'); 134 } 135 return await ExpoApplication.getApplicationReleaseTypeAsync(); 136} 137 138// @docsMissing 139export type PushNotificationServiceEnvironment = 'development' | 'production' | null; 140 141// @needsAudit 142/** 143 * Gets the current [Apple Push Notification (APN)](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment?language=objc) 144 * service environment. 145 * @return Returns a promise fulfilled with the string, either `'development'` or `'production'`, 146 * based on the current APN environment, or `null` on the simulator as it does not support registering with APNs. 147 * @platform ios 148 */ 149export async function getIosPushNotificationServiceEnvironmentAsync(): Promise<PushNotificationServiceEnvironment> { 150 if (!ExpoApplication.getPushNotificationServiceEnvironmentAsync) { 151 throw new UnavailabilityError('expo-application', 'getPushNotificationServiceEnvironmentAsync'); 152 } 153 return await ExpoApplication.getPushNotificationServiceEnvironmentAsync(); 154} 155 156// @needsAudit 157/** 158 * Gets the time the app was installed onto the device, not counting subsequent updates. If the app 159 * is uninstalled and reinstalled, this method returns the time the app was reinstalled. 160 * - On iOS, this method uses the [`NSFileCreationDate`](https://developer.apple.com/documentation/foundation/nsfilecreationdate?language=objc) 161 * of the app's document root directory. 162 * - On Android, this method uses [`PackageInfo.firstInstallTime`](https://developer.android.com/reference/android/content/pm/PackageInfo.html#firstInstallTime). 163 * - On web, this method returns `null`. 164 * 165 * @return Returns a `Promise` that fulfills with a `Date` object that specifies the time the app 166 * was installed on the device. 167 * 168 * @example 169 * ```ts 170 * await Application.getInstallationTimeAsync(); 171 * // 2019-07-18T18:08:26.121Z 172 * ``` 173 */ 174export async function getInstallationTimeAsync(): Promise<Date> { 175 if (!ExpoApplication.getInstallationTimeAsync) { 176 throw new UnavailabilityError('expo-application', 'getInstallationTimeAsync'); 177 } 178 const installationTime = await ExpoApplication.getInstallationTimeAsync(); 179 return new Date(installationTime); 180} 181 182// @needsAudit 183/** 184 * Gets the last time the app was updated from the Google Play Store. 185 * @return Returns a `Promise` that fulfills with a `Date` object that specifies the last time 186 * the app was updated via the Google Play Store). 187 * 188 * @example 189 * ```ts 190 * await Application.getLastUpdateTimeAsync(); 191 * // 2019-07-18T21:20:16.887Z 192 * ``` 193 * @platform android 194 */ 195export async function getLastUpdateTimeAsync(): Promise<Date> { 196 if (!ExpoApplication.getLastUpdateTimeAsync) { 197 throw new UnavailabilityError('expo-application', 'getLastUpdateTimeAsync'); 198 } 199 const lastUpdateTime = await ExpoApplication.getLastUpdateTimeAsync(); 200 return new Date(lastUpdateTime); 201} 202