Get AssetTrackingCallback ViewController
This example will provide step-by-step guidance on:
-
Initializing Configurations with Default Values: Learn how to set up all configurations using default values, simplifying the integration process and ensuring a seamless start.
-
Creating and Binding a Simple Asset while Initiating Tracking: Discover how to create a basic asset, bind it to your application, and kickstart the tracking process, enabling real-time monitoring of asset locations.
-
Receiving AssetTrackingCallback in Your ViewController: Understand how to receive and utilize AssetTrackingCallback in your ViewController, enabling you to respond to tracking events and location updates effectively.
For all code examples, refer to iOS Tracking Android Code Examples
GetAssetCallbackViewController view source
Upon executing the code example provided above, your app's appearance will resemble the following snippet:
Code Highlights
The above code snippet is a class inherited from the UIViewController class, which is the base class for all view controllers in iOS.
-
The class also conforms to the AssetTrackingCallback protocol, which means that the class will receive callbacks from the AssetTracking class.
-
The class has four outlet properties: startTrackingBtn, stopTrackingBtn, trackingStatus, and locationInfo. These properties are linked to the corresponding UI elements in the view controller's storyboard.
-
The class has two methods to start and stop tracking the asset. These methods call the AssetTracking.shared.startTracking() and AssetTracking.shared.stopTracking() methods, respectively.
-
The class has six methods to handle the callbacks from the AssetTracking class. These methods are:
-
onTrackingStart(assetId: String): This method is called when the tracking for the asset starts.
-
onTrackingStop(assetId: String, trackingDisableType: NBAssetTracking.TrackingDisableType): This method is called when the tracking for the asset stops.
-
onLocationSuccess(location: CLLocation): This method is called when the location of the asset is successfully retrieved.
-
onLocationFailure(error: Error): This method is called when the location of the asset cannot be retrieved.
-
onLocationServiceOff(): This method is called when the location services are turned off.
-
showLocationAlert(): This method shows an alert to the user to turn on the location services.
-
Here is a more detailed explanation of some of the key concepts in the code:
-
AssetTracking: This is the class that is responsible for tracking assets.
-
AssetTrackingCallback: This is a protocol that must be adopted by classes that want to receive callbacks from the AssetTracking class.
-
CLLocation: This is a class that represents a location on Earth.