1import { Platform, 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 * Gets 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 function is unavailable. 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 function getAndroidId(): string { 66 if (Platform.OS !== 'android') { 67 throw new UnavailabilityError('expo-application', 'androidId'); 68 } 69 return ExpoApplication.androidId; 70} 71 72// @needsAudit 73/** 74 * Gets the referrer URL of the installed app with the [`Install Referrer API`](https://developer.android.com/google/play/installreferrer) 75 * from the Google Play Store. In practice, the referrer URL may not be a complete, absolute URL. 76 * @return A `Promise` that fulfills with a `string` of the referrer URL of the installed app. 77 * 78 * @example 79 * ```ts 80 * await Application.getInstallReferrerAsync(); 81 * // "utm_source=google-play&utm_medium=organic" 82 * ``` 83 * @platform android 84 */ 85export async function getInstallReferrerAsync(): Promise<string> { 86 if (!ExpoApplication.getInstallReferrerAsync) { 87 throw new UnavailabilityError('expo-application', 'getInstallReferrerAsync'); 88 } 89 return await ExpoApplication.getInstallReferrerAsync(); 90} 91 92// @needsAudit 93/** 94 * Gets the iOS "identifier for vendor" ([IDFV](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor)) 95 * value, a string ID that uniquely identifies a device to the app’s vendor. This method may 96 * sometimes return `nil`, in which case wait and call the method again later. This might happen 97 * when the device has been restarted before the user has unlocked the device. 98 * 99 * The OS will change the vendor identifier if all apps from the current app's vendor have been 100 * uninstalled. 101 * 102 * @return A `Promise` that fulfills with a `string` specifying the app's vendor ID. Apps from the 103 * same vendor will return the same ID. See Apple's documentation for more information about the 104 * vendor ID's semantics. 105 * 106 * @example 107 * ```ts 108 * await Application.getIosIdForVendorAsync(); 109 * // "68753A44-4D6F-1226-9C60-0050E4C00067" 110 * ``` 111 * @platform ios 112 */ 113export async function getIosIdForVendorAsync(): Promise<string | null> { 114 if (!ExpoApplication.getIosIdForVendorAsync) { 115 throw new UnavailabilityError('expo-application', 'getIosIdForVendorAsync'); 116 } 117 return (await ExpoApplication.getIosIdForVendorAsync()) ?? null; 118} 119 120// @docsMissing 121export enum ApplicationReleaseType { 122 UNKNOWN = 0, 123 SIMULATOR = 1, 124 ENTERPRISE = 2, 125 DEVELOPMENT = 3, 126 AD_HOC = 4, 127 APP_STORE = 5, 128} 129 130// @needsAudit 131/** 132 * Gets the iOS application release type. 133 * @return Returns a promise which fulfills with an [`ApplicationReleaseType`](#applicationreleasetype). 134 * @platform ios 135 */ 136export async function getIosApplicationReleaseTypeAsync(): Promise<ApplicationReleaseType> { 137 if (!ExpoApplication.getApplicationReleaseTypeAsync) { 138 throw new UnavailabilityError('expo-application', 'getApplicationReleaseTypeAsync'); 139 } 140 return await ExpoApplication.getApplicationReleaseTypeAsync(); 141} 142 143// @docsMissing 144export type PushNotificationServiceEnvironment = 'development' | 'production' | null; 145 146// @needsAudit 147/** 148 * Gets the current [Apple Push Notification (APN)](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment?language=objc) 149 * service environment. 150 * @return Returns a promise fulfilled with the string, either `'development'` or `'production'`, 151 * based on the current APN environment, or `null` on the simulator as it does not support registering with APNs. 152 * @platform ios 153 */ 154export async function getIosPushNotificationServiceEnvironmentAsync(): Promise<PushNotificationServiceEnvironment> { 155 if (!ExpoApplication.getPushNotificationServiceEnvironmentAsync) { 156 throw new UnavailabilityError('expo-application', 'getPushNotificationServiceEnvironmentAsync'); 157 } 158 return await ExpoApplication.getPushNotificationServiceEnvironmentAsync(); 159} 160 161// @needsAudit 162/** 163 * Gets the time the app was installed onto the device, not counting subsequent updates. If the app 164 * is uninstalled and reinstalled, this method returns the time the app was reinstalled. 165 * - On iOS, this method uses the [`NSFileCreationDate`](https://developer.apple.com/documentation/foundation/nsfilecreationdate?language=objc) 166 * of the app's document root directory. 167 * - On Android, this method uses [`PackageInfo.firstInstallTime`](https://developer.android.com/reference/android/content/pm/PackageInfo.html#firstInstallTime). 168 * - On web, this method returns `null`. 169 * 170 * @return Returns a `Promise` that fulfills with a `Date` object that specifies the time the app 171 * was installed on the device. 172 * 173 * @example 174 * ```ts 175 * await Application.getInstallationTimeAsync(); 176 * // 2019-07-18T18:08:26.121Z 177 * ``` 178 */ 179export async function getInstallationTimeAsync(): Promise<Date> { 180 if (!ExpoApplication.getInstallationTimeAsync) { 181 throw new UnavailabilityError('expo-application', 'getInstallationTimeAsync'); 182 } 183 const installationTime = await ExpoApplication.getInstallationTimeAsync(); 184 return new Date(installationTime); 185} 186 187// @needsAudit 188/** 189 * Gets the last time the app was updated from the Google Play Store. 190 * @return Returns a `Promise` that fulfills with a `Date` object that specifies the last time 191 * the app was updated via the Google Play Store). 192 * 193 * @example 194 * ```ts 195 * await Application.getLastUpdateTimeAsync(); 196 * // 2019-07-18T21:20:16.887Z 197 * ``` 198 * @platform android 199 */ 200export async function getLastUpdateTimeAsync(): Promise<Date> { 201 if (!ExpoApplication.getLastUpdateTimeAsync) { 202 throw new UnavailabilityError('expo-application', 'getLastUpdateTimeAsync'); 203 } 204 const lastUpdateTime = await ExpoApplication.getLastUpdateTimeAsync(); 205 return new Date(lastUpdateTime); 206} 207