Skip to main content

Unity Wrapper SDK

This is the documentation for the Unity wrapper module, which provides a thin proxy layer for integrating existing native SDKs offering location tracking and geofencing services. Before integrating, review the native SDK documentation for iOS and Android to understand platform-specific requirements and features.

The Unity wrapper is developed as a plugin for native SDKs written in Kotlin for Android and Objective-C for iOS. Wrappers for .NET MAUI, React Native, Flutter, and Capacitor are also available.

See the source on GitHub here.

Supported Unity Versions#

The SDK has been tested on Unity 2022.3.41f, and 6000.0.24f versions. However, it should work with Unity versions 2021 and above.

Project Structure#

The project directory is organized as follows:

Assets/└── ExternalDependencyManager/   ├── Editor/   ...└── Plugins/   ├── Android/   │   ├── sdk-debug.aar   │   └── Dependencies.xml   │   └── gradleTemplate.properties   │   └── mainTemplate.gradle   │   └── settingsTemplate.gradle   ├── iOS/   │   ├── RadarSDK.xcframework   │   ├── RadarUnityBridge.m└── Radar/   └── Demo/   │   ├── Icons/   │   ├── Prefabs/   │   ├── Scenes/   │   ├── Scripts/   └── Resources/   │   ├── Editor/   │   ├── Settings/   ├── Scripts/   │   ├── iOS/   │   ├── Android/   │   └── Models/   │   └── ProxyPlatform/

Install#

To integrate the Unity wrapper, download or clone the package and include it in your Unity project:

  1. Copy the Plugins folder (containing both Android and iOS native implementations) into the Assets directory of your Unity project.
  2. Import the ExternalDependencyManager for Unity (EDM4U). You can get it from Package Manager or from repo: It is required if you want to add and use iOS/Android dependencies directly in your project like: Android specific libraries (e.g AARs) or iOS CocoaPods
  3. Ensure that any required permissions or settings specific to location tracking and geofencing are configured on both iOS and Android, as outlined in the native SDK documentation.

iOS#

  1. To install the iOS SDK, navigate to your iOS project directory:

    cd ios/
  2. In your Podfile, ensure that platform :ios is set to 10.0 or higher. Then, install the required pods:

    pod install

    You must add location usage descriptions and enable background modes in your Info.plist file as described in the iOS SDK documentation. This is essential for accessing location services and geofencing in the background.

  3. To handle location updates effectively, configure background processing options if your app requires tracking location changes when the app is not actively in use.

info

Don't forget to include RadarSDK.xcframework under Your Project General > Frameworks, Libraries, and Embedded Content when building application in XCode.

Android#

  1. To integrate with the Android SDK, update your app’s build.gradle file to include Google Play Services Location. Ensure you are using version 21.0.1 or higher:

    implementation "com.google.android.gms:play-services-location:21.0.1"
  2. Configure permissions and background processing for location services in your AndroidManifest.xml. Add the necessary permissions for foreground and background location access:

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

    Refer to the Android SDK documentation for detailed setup on background tracking and ensuring compliance with Play Store policies regarding location permissions.

Integrate#

Using plugin#

Once installed, access the SDK functionality using RadarSDK namespace:

using RadarSDK;

Calls to APIs#

The Unity SDK exposes following APIs calls:

initialize, setUserId, getUserId, setMetadata, getLocation, trackVerified, startTrackingVerified, stopTracking, getVerifiedLocationToken, onTokenUpdated

Look at RadarExample.cs script for example usages

Initialize#

Initialize

// Coroutine Callprivate void InitializeRadar(){   StartCoroutine(RadarSDKManager.Initialize());}
// Async Callprivate async Task InitializeRadarAsync(){   await RadarSDKManager.InitializeAsync();}

SetUserId#

SetUserId

// Coroutine Callpublic void SetUserId(string userId){   RadarSDKManager.SetUserId(userId);}
// Async Callprivate async Task SetUserIdAsync(string userId){   await RadarSDKManager.SetUserIdAsync(userId);}

SetMetadata#

SetMetadata

// Coroutine Callpublic void SetMetadata(MetadataContainer metadata){   RadarSDKManager.SetMetadata(metadata);}
// Async Callprivate async Task SetMetadataAsync(MetadataContainer metadata){   await RadarSDKManager.SetMetadataAsync(metadata);}

GetLocation#

GetLocation

// Coroutine Callpublic void GetLocation(){   StartCoroutine(GetLocationCoroutine());}
// Async Callprivate IEnumerator GetLocationCoroutine(){   var task = RadarSDKManager.GetLocationAsync();
   while (!task.IsCompleted)         yield return null;
   if (task.Result != null)         Debug.Log($"Location: Latitude = {task.Result.Value.latitude}, Longitude = {task.Result.Value.longitude}");   else         Debug.LogError("Failed to retrieve location.");}

TrackVerified#

TrackVerified

// Coroutine Callpublic void TrackVerified(){   StartCoroutine(RadarSDKManager.TrackVerified());}
// Async Callprivate async Task TrackVerifiedAsync(){   await RadarSDKManager.TrackVerifiedAsync(RadarSDKManager.UserId);}

StartTrackingVerified#

StartTrackingVerified

// Coroutine Callpublic void StartTrackingVerified(){   StartCoroutine(RadarSDKManager.StartTrackingVerified());}
// Async Callprivate async Task StartTrackingVerifiedAsync(){   await RadarSDKManager.StartTrackingVerifiedAsync(RadarSDKManager.TrackingInterval, RadarSDKManager.UseBeacons);}

StopTracking#

StopTracking

// Coroutine Callpublic void StopTracking(){   StartCoroutine(RadarSDKManager.StopTracking());}
// Async Callprivate async Task StopTrackingAsync(){   await RadarSDKManager.StopTrackingAsync();}

GetVerifiedLocationToken#

Once the native SDK retrieves the location, it sends the data back to Unity. On Android, this is done via RadarJavaProxy, and on iOS, it’s done via a delegate or callback defined in RadarUnityBridge.m

// Coroutine Callpublic void GetVerifiedLocationToken(){   StartCoroutine(GetVerifiedLocationTokenCoroutine());}

private IEnumerator GetVerifiedLocationTokenCoroutine(){   var task = RadarSDKManager.GetVerifiedLocationTokenAsync();   while (!task.IsCompleted)         yield return null;
   if (task.Result.HasValue)         Debug.Log($"Verified Location Token received: Status = {task.Result.Value.Status}");   else         Debug.LogError("Failed to retrieve verified location token.");}
// Async Callprivate async Task GetVerifiedLocationTokenAsync(){   var result = await RadarSDKManager.GetVerifiedLocationTokenAsync();   if (result.HasValue)         Debug.Log($"Verified Location Token received: Status = {result.Value.Status}");   else         Debug.LogError("Failed to retrieve verified location token.");}

OnTokenUpdated#

OnTokenUpdated callback

// Coroutine Callpublic void SetVerifiedReceiver(){   RadarSDKManager.SetVerifiedReceiver(OnVerifiedLocationTokenReceived);}
private void OnVerifiedLocationTokenReceived(RadarVerifiedLocationToken token){   Debug.Log($"Verified location token updated: {token}");}

Support#

Have questions? We're here to help! Contact us at radar.com/support.