Advertisement
Badal_hs_shah

location permission

Jan 20th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class LocationService {
  2.   static async getDefaultParams() {
  3.     check(PERMISSIONS.IOS.LOCATION_ALWAYS)
  4.       .then(result => {
  5.         switch (result) {
  6.           case RESULTS.UNAVAILABLE:
  7.             console.log(
  8.               'This feature is not available (on this device / in this context)',
  9.             );
  10.             break;
  11.           case RESULTS.DENIED:
  12.             console.log(
  13.               'The permission has not been requested / is denied but requestable',
  14.             );
  15.             break;
  16.           case RESULTS.LIMITED:
  17.             console.log('The permission is limited: some actions are possible');
  18.             return permissionStatus();
  19.           case RESULTS.GRANTED:
  20.             return permissionStatus();
  21.           case RESULTS.BLOCKED:
  22.             console.log('The permission is denied and not requestable anymore');
  23.             break;
  24.         }
  25.       })
  26.       .catch(error => {
  27.         // …
  28.       });
  29.  
  30.     async function permissionStatus() {
  31.       let location;
  32.       try {
  33.         // Get current location
  34.         location = await Geolocation.getCurrentPosition(
  35.           position => position.coords,
  36.           error => {
  37.             console.log(error.message);
  38.           },
  39.           {enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},
  40.         );
  41.       } catch (err) {
  42.         console.log(err);
  43.       }
  44.       if (location) {
  45.         // Return default params
  46.         return {
  47.           MachineName: 'iPhone 14',
  48.           ApplicationVersion: '12.1.4',
  49.           BatteryLevelPercent: '-100',
  50.           DiskSpaceAvailableInMB: '82641.23',
  51.           DiskSpaceSizeInMB: '233752.4',
  52.           CarrierName: 'Unknown',
  53.           DeviceModel: 'x86_64',
  54.           BatteryState: 'Unknown',
  55.           Latitude: location.latitude,
  56.           AllowFirmwareUpgrade: 'true',
  57.           ConnectionType: 'WiFi',
  58.           OsVersion: '16.0',
  59.           IsUploadNeeded: 'false',
  60.           Longitude: location.longitude,
  61.           DeviceType: 'iPhone',
  62.           DeviceGuid: '1A5FAF66-EAA7-488A-A518-99321BB2FB59',
  63.         };
  64.       } else {
  65.         return undefined;
  66.       }
  67.     }
  68.   }
  69. }
  70.  
  71. export default LocationService;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement