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
  • You will need to get Always authorization from an instance of CLLocationManager

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

override func viewDidAppear(_ animated: Bool) {
    let controller = NITPermissionsViewController()
    controller.delegate = self
    controller.show()
}
- (void)viewDidAppear:(BOOL)animated
{
     [super viewDidAppear:animated];
     NITPermissionsViewController *controller = [[NITPermissionsViewController alloc] init];
    controller.delegate = self;
    [controller show];
}

This will produce this behaviour:

permissions

You can check that the user granted all the permissions in the dialogClosed:locationGranted:notificationsGranted: method of the NITPermissionsViewControllerDelegate and then start the NearIT location features:

func dialogClosed(locationGranted: Bool, notificationsGranted: Bool) {
    if (locationGranted && notificationsGranted) {
        NITManager.default().start()
    }
}
- (void)dialogClosed:(BOOL)locationGranted notificationGranted:(BOOL)notificationGranted {
    if (locationGranted && notificationGranted) {
        [NITManager.defaultManager start];
    }
}

You are now able to test this type of notifications! You should create a recipe in your sandbox environment and see that you will receive a notification when you enter a geofence.

You can learn how to customize the look and behaviour of our permission dialog in this section.

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