Skip to content

iOS Configuration

Edit AppDelegate.m

Edit your project ios/<app-name>/AppDelegate.m as follow

  • add the following import (after the React ones)
#import "RNNearIt.h"
  • add RNNearIT notification handling methods
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  // ReactNative initialization code
  ...

  [RNNearIt registerForRemoteNotifications];
  [RNNearIt application:application didFinishLaunchingWithOptions:launchOptions];

  return YES;
}

...

- (void)application:(UIApplication*) application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [RNNearIt didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication*) application didReceiveLocalNotification:(UILocalNotification *)notification {
  [RNNearIt didReceiveLocalNotification:notification];
}

- (void)application:(UIApplication*) application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  [RNNearIt didReceiveRemoteNotification:userInfo];
}


Request Notification permission

Both Location Based Notifications and Push Notifications require the user to grant the proper permission.

To check if the user granted permission:

import NearITPermissions from 'react-native-nearit'
...
NearITPermissions.checkNotification().then( status => {
  switch(status) {
    case 'always':
      // user already granted the permission
      break;
    case 'denied':
      // user already denied the permission
      break;
    case 'never_asked':
      // you never asked for permission
      break;
  }
}

To ask the user for notification permission you can use the provided method:

import NearITPermissions from 'react-native-nearit'
...
NearITPermissions.requestNotification().then( result => {
  switch(result) {
    case 'always':
      // user granted the permission
      break;
    case 'denied':
      // user denied the permission
      break;
  }
});

Note: calling NearITPermissions.requestNotification() when the user previously denied permission will open app settings.


Auto update

To make the SDK periodically check for new content, you have to follow these steps.

  • Inside Xcode, navigate to the “Capabilities” tab of your app. You will need to enable “Background Modes” capability and check "Background fetch".

capabilities

  • add RNNearIT background fetch handling method to your AppDelegate.m
...

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  [RNNearIt application:application performFetchWithCompletionHandler:completionHandler];
}

@end