Skip to content

Installation

Minimum Requirements:

  • Deployment target: iOS 9+

Add the NearIT pod in your Podfile

pod 'NearITSDKSwift'
pod 'NearUIBinding'
pod 'NearITSDK'
pod 'NearUIBinding'

Set the API token to the SDK as a String, in the application:didFinishLaunchingWithOptions: method of your AppDelegate class.

import NearITSDKSwift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    ...
    NearManager.setup(apiKey: "your API token here")
    let manager = NearManager.shared
    ...
}
#import "NearITSDK/NearITSDK.h";

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [NITManager setupWithApiKey:@"your API token here"];
    NITManager *manager = [NITManager defaultManager];
    ...
}

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

Auto update

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

First thing to do is to enable the feature background fetch in the capabilities section of your app project.

capabilities

Call the method application:performFetchWithCompletionHandler of the Near manager, in the application:performFetchWithCompletionHandler of your AppDelegate class:

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    nearManager.application(application) { (fetchResult) in
        completionHandler(fetchResult)
    }
}
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [nearManager application:application performFetchWithCompletionHandler:^(UIBackgroundFetchResult result) {
        completionHandler(result);
    }];
}

Then set the minimun background fetch interval in the application:didFinishLaunchingWithOptions method of your AppDelegate class (2 hours is the recommended value):

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    ...
    application.setMinimumBackgroundFetchInterval(7200) // 2 hours
    ...
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [application setMinimumBackgroundFetchInterval:7200]; // 2 hours
    ...
}

Enable test devices

Test Devices allow you to test NearIT features on single devices and is extremely useful for debugging.

Navigate "Settings > Test devices" section of NearIT and follow the instructions to enable this feature. The procedure will make you update your 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:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return NearManager.shared.application(app, open: url, options: options)
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    [[NITManager defaultManager] application:app openURL:url options:options];
}