Skip to content

Installation

To install NearIT, click on “Project>Add NuGet Packages”, make sure you have "Show pre-release packages" option checked, find and add the following NuGet packages:

- Xamarin.NearIT.PCL        (in your common fragment)
- Xamarin.NearIT.iOS        (in your native iOS fragment)
- Xamarin.NearIT.Android    (in your native Android fragment)

NOTE: Make sure that your Android target framework is set to at least 8.1 and the minimum iOS version is at least 10.

You can find the API key on NearIT web interface, under the "Settings>SDK Integration" section. You will use it to configure both the Android and the iOS modules.

Android

In your AndroidManifest.xml, under the Source tab, add the following permission:

<uses-permission android:name="android.permission.INTERNET" />

Also, add your NearIT API-Key in the application element.

<meta-data android:name="near_api_key" android:value="REPLACE-WITH-YOUR-KEY" />

and paste the following code:

<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="${applicationId}" />
    </intent-filter>
</receiver>

WARNING:

In both Debug and Release mode, make sure you have Multi-Dex enabled in the “Options>Android Build” settings.

Enable Test Device

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

Navigate to the "Settings > Test devices" section of NearIT to find the snippet for your AndroidManifest.xml.

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.


iOS

In the FinishedLaunching method of your AppDelegate class, initialize the SDK with the API token:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    ...
    // call this BEFORE LoadApplication(new App());
    NearBridgeiOS.Init("<your API token here>");
    ...
}

Enable the background fetch feature in the capabilities section of your app project. See the official xamarin documentation on the subject.

Call the method PerformFetch of the NearBridgeiOS, in the PerformFetch method of your AppDelegate class:

public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
    NearBridgeiOS.PerformFetch(application, completionHandler);
}

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

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    ...
    UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(MINIMUM_BACKGROUND_FETCH_INTERVAL);    
    //MINIMUM_BACKGROUND_FETCH_INTERVAL usually set to 7200
    ...
}

Enable Test Device

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

Navigate to the "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:

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
    return NITManager.DefaultManager.Application(app, url, options as NSDictionary<NSString, NSObject>);
}