Skip to content

iOS Configuration

Step 1: Edit/create the Podfile

If you don't have a Podfile, create it in ios folder with the following content:

platform :ios, '9.0'

use_frameworks!
use_modular_headers!

workspace '<YourAppName>.xcworkspace'   # <-- replace <YourAppName>

def near_pods
  pod 'NearITSDK', '~> 2.12.1'
  pod 'NearITSDKSwift', '~> 2.12.1'
  pod 'NearUIBinding', '~> 2.12.1'
end

target 'ReactNativeSampleTwo' do
  near_pods

  rn_path = '../node_modules/react-native'

  pod 'yoga', path: "#{rn_path}/ReactCommon/yoga"
  pod 'React', path: rn_path, subspecs: [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
  ]
  pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"

  # Add new pods below this line
  pod 'RNNearIt', :path => '../node_modules/react-native-nearit'

  target 'RNNearIt' do
    near_pods
    project '../node_modules/react-native-nearit/ios/RNNearIt.xcodeproj'
    inherit! :search_paths
  end

end

Step 2: Install native dependencies

Run

$ pod repo update

and

$ pod install

commands from ios folder.

If not already added, drag the RNNearIt.xcodeproj you will find in node_modules/react-native-nearit/ios into Libraries group in Xcode.

ioslinkproject

Add the static library (libRNNearIt.a) to Linked Frameworks and Libraries

ioslinklibrary

Step 4: Override methods

Edit your project ios/<YourAppName>/AppDelegate.h and make the class implement UNUserNotificationCenterDelegate protocol:

// ...
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

and in ios/<app-name>/AppDelegate.m override these methods:

#import "RNNearIt.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // ...

  [UNUserNotificationCenter currentNotificationCenter].delegate = self;

  return YES;
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
  [[RNNearIt defaultManager] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
  [[RNNearIt defaultManager] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}

Step 5: NearIT Api Key

Create the NearIt.plist file (with exactly this name) at ios/<your app name>/NearIt.plist to specify your API Key

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>API Key</key>
        <string>Your.API.Key</string>
    </dict>
</plist>

You can find your API key on NearIT web interface, under the "SDK Integration" section.

N.B: We suggests you to ignore this file from your versioning system.

Step 6: Test devices

Go to NearIT web interface, navigate to "Settings > Test devices" and follow instructions to enable this feature. The procedure will make you update your ios/<YourAppName>/Info.plist file to include a CFBundleURLSchemes.

In the same section, you can send invite links to mail addresses. If users have the app installed, they can click the link on their smart-phone to be prompted with a request to enroll their device among the testers.

After the Info.plist update, you must override the AppDelegate method for url management:

#import "RNNearIt.h"

// ...

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    return [[RNNearIt defaultManager] application:app openUrl:url options:options];
}

(Optional) Step 7: 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 defaultManager] application:application performFetchWithCompletionHandler:completionHandler];
}