1import { UnavailabilityError } from '@unimodules/core'; 2import { PermissionStatus } from 'expo-modules-core'; 3import { Platform } from 'react-native'; 4import ExpoTrackingTransparency from './ExpoTrackingTransparency'; 5const androidAndWebPermissionsResponse = { 6 granted: true, 7 expires: 'never', 8 canAskAgain: true, 9 status: PermissionStatus.GRANTED, 10}; 11/** 12 * Requests the user to authorize or deny access to app-related data that can be used for tracking 13 * the user or the device. Examples of data used for tracking include email address, device ID, 14 * advertising ID, etc. On iOS 14.5 and above, if the user denies this permission, any attempt to 15 * collect the IDFA will return a string of 0s. 16 * 17 * The system remembers the user’s choice and doesn’t prompt again unless a user uninstalls and then 18 * reinstalls the app on the device. 19 * 20 * On Android, web, and iOS 13 and below, this method always returns that the permission was 21 * granted. 22 * @example 23 * ```typescript 24 * const { granted } = await requestTrackingPermissionsAsync(); 25 * 26 * if (granted) { 27 * // Your app is authorized to track the user or their device 28 * } 29 * ``` 30 */ 31export async function requestTrackingPermissionsAsync() { 32 if (Platform.OS !== 'ios') { 33 return Promise.resolve(androidAndWebPermissionsResponse); 34 } 35 if (!ExpoTrackingTransparency.requestPermissionsAsync) { 36 throw new UnavailabilityError('TrackingTransparency', 'requestPermissionsAsync'); 37 } 38 return await ExpoTrackingTransparency.requestPermissionsAsync(); 39} 40/** 41 * Checks whether or not the user has authorized the app to access app-related data that can be used 42 * for tracking the user or the device. See `requestPermissionsAsync` for more details. 43 * 44 * On Android, web, and iOS 13 and below, this method always returns that the permission was 45 * granted. 46 * 47 * @example 48 * ```typescript 49 * const { granted } = await getTrackingPermissionsAsync(); 50 * 51 * if (granted) { 52 * // Your app is authorized to track the user or their device 53 * } 54 * ``` 55 */ 56export async function getTrackingPermissionsAsync() { 57 if (Platform.OS !== 'ios') { 58 return Promise.resolve(androidAndWebPermissionsResponse); 59 } 60 if (!ExpoTrackingTransparency.getPermissionsAsync) { 61 throw new UnavailabilityError('TrackingTransparency', 'getPermissionsAsync'); 62 } 63 return await ExpoTrackingTransparency.getPermissionsAsync(); 64} 65/** 66 * Returns whether the TrackingTransparency API is available on the current device. 67 * 68 * @returns Currently this is `true` on iOS 14 and above only. On devices where the 69 * Tracking Transparency API is unavailable, the get and request permissions methods will always 70 * resolve to `granted`. 71 */ 72export function isAvailable() { 73 return (Platform.OS === 'ios' && 74 parseInt(Platform.Version.toString(), 10) >= 14 && 75 ExpoTrackingTransparency); 76} 77export { PermissionStatus }; 78//# sourceMappingURL=TrackingTransparency.js.map