Skip to content

Location Based Notifications

Before you start:

  • You must add the NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription in the project Info.plist
  • For iOS 11 you must add the NSLocationAlwaysAndWhenInUseUsageDescription in the project Info.plist

Ask for the proper permissions, then you can call the following method to start the radar for geofences and beacons:

// call this ONLY when you are given location permission
NearIT.startRadar()

Note: Location permission request is an important task and you should handle various scenarios, depending on platform (Android, iOS) and OS version.

Please consider using the following method:

import NearITPermissions from 'react-native-nearit'
...
NearITPermissions.requestLocation().then( result => {
  switch (result) {
    case 'always':
      //  optimal place to call NearIT.startRadar()
      break;
    case 'when_in_use':
      //  still a good place to call NearIT.startRadar()
      break;
    default:
      //  DO NOT start NearIT radar!
  }
});

We also provide a useful method to check location permission status:

import NearITPermissions from 'react-native-nearit'
...
NearITPermissions.checkLocation().then( status => {
  switch (status) {
    case 'always':
      // ...
      break;
    case 'when_in_use':
      // ...
      break;
    case 'denied':
      // ...
      break;
    case 'never_asked':
      // ...
      break;
  }
});

Please, check this module out. It provides useful methods to check location and bluetooth services.