Getting started
To begin your journey with NextBillion.ai's Asset Tracking iOS SDK, make sure you have met the necessary prerequisites, as outlined in the "Prerequisites" section. Then, proceed with the step-by-step installation instructions to integrate the SDK into your iOS project.
Prerequisites
Before integrating the SDK into your application, ensure that your development environment meets the following prerequisites:
-
NextBillion.ai API Key: Obtain a valid access key from our platform. This access key is essential for authentication and enables you to utilize the SDK's services.
-
Platform Compatibility: Make sure you're using the right tools and versions:
-
IDE: Xcode 13.2.1 or a more recent version.
-
Minimum Deployment Target: iOS 11.0.
-
-
Location Data Access Explanation: In your
Info.plist, add the required location permission keys.
By meeting these prerequisites, you can guarantee a smooth and successful integration of our SDK into your application. These requirements have been established to ensure compatibility and optimal performance, enabling you to leverage the full potential of the SDK's features.
Installation
Installation steps are streamlined for faster integration, aligned with mainstream SDK docs (SPM-first, optional alternatives).
Quick Integration (Recommended)
- Add SDK dependency (SPM recommended).
- Configure Info.plist permissions.
- Initialize SDK with apiKey.
- Create/Bind assets and start tracking.
Install SDK via Carthage (Optional)
Carthage is kept for existing projects only. If your project already uses Carthage, keep using it. For new projects, use Swift Package Manager.
Carthage reference: https://github.com/Carthage/Carthage#installing-carthage
Carthage Quick Steps
-
Create Cartfile and add dependencies below:
Cartfile example:
-
Run Carthage update command below:
-
Link and embed listed frameworks in Xcode target
Install SDK via Swift Package Manager (Recommended)
Recommended for all new integrations.
- In Xcode, go to
File>Add Package Dependencies.... - Enter package URL: https://github.com/nextbillion-ai/asset-tracking-distribution
- Add product
NBAssetTrackingto your app target (Version: 1.4.1 or Up to Next Major from 1.4.1). - Import SDK:
import NBAssetTracking.
Install SDK via CocoaPods (Optional)
Use this only if your project already uses CocoaPods.
-
Podfile example:
-
Run
pod repo update && pod install, then open the.xcworkspacefile.
After dependency installation, continue with Initialization and Asset Binding sections.
Location Data Access Explanation
Add the following to the Info.plist to explain why you need access to the location data:
Initialization
A common way to initialize the SDK is to put the following code in your AppDelegate, otherwise, please make sure you have called the code below before you start using any functionalities of the SDK.
Replace YOUR_ACCESS_KEY with the access key provided to you by NextBillion.ai. This initialization step is essential to authenticate your app and enable seamless communication with NextBillion.ai's services.
Asset Binding and Tracking
To initiate asset binding and tracking with the NextBillion.ai iOS Tracking SDK, follow these steps:
Creating an Asset
If you don't have an asset yet, you can create one using the following API: AssetTracking.shared.createAsset(baseUrl, assetProfile, completionHandler, errorHandler)
Retrieve the assetId from the API response.
Here's a sample class structure for handling the response:
Binding the Asset to Your Device
Once you have the assetId, use the following API to bind the asset to your current device:
After a successful binding, you're ready to start tracking the location of the asset.
Start and Stop Tracking
You have the flexibility to initiate or halt tracking on your device, with location tracking and uploading adhering to your predefined configurations:
To start data tracking:
To stop data tracking:
By following these steps, you'll effectively bind assets to your iOS device and commence location tracking as per your configuration settings. This allows you to seamlessly monitor and manage your assets using the NextBillion.ai iOS Tracking SDK.