Skip to content

Location Based Notifications

Before you start:

  • You must add the NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription in tiapp.xml, for iOS 11 you must add the NSLocationAlwaysAndWhenInUseUsageDescription too:
...
<ios>
  ...
  <plist>
    ...
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>YOUR MESSAGE FOR 'Always' AND 'WhenInUse' PERMISSION</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>YOUR MESSAGE FOR 'Always' PERMISSION</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>YOUR MESSAGE FOR 'WhenInUse' PERMISSION</string>
    ...
  </plist>
  ...
</ios>
...

You can ask for notification and location permissions, using our drop-in permission dialog:

NearIT.requestPermissions({
  // optional
  explanation: "YOUR MESSAGE THAT EXPLAINS WHY YOU ARE REQUESTING THESE PERMISSIONS",

  dialogClosed: function(result) {

    if (result.location) {
      console.log("location granted");

      //  Start NearIT radar
      NearIT.startRadar();
    }

    if (result.notifications) {
      console.log("notifications granted");
    }
  }
});

This will produce this behaviour:

permissions

You can check if the user granted all the permissions in the dialogClosed callback and then start the NearIT location features.

Also, if you have your own permission request flow, just remember to call the method NearIT.startRadar() after your app has acquired the proper permissions.