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