Asset profile Operations
This example demonstrates:
-
Creating an Asset: Learn how to generate a new asset within your application, enabling the introduction of new assets into your tracking system.
-
Binding an Existing Asset ID to the Current Device: Discover the process of associating an existing asset ID with the device you're currently using, facilitating tracking and management of that asset.
-
Updating the Current Asset Profile: Gain insights into how to modify the profile of an asset, ensuring that the asset's information remains accurate and up-to-date.
-
Retrieving Asset Details for the Bound Asset ID: Learn how to access and retrieve detailed information about an asset that has been successfully bound to the current device, enabling comprehensive asset management.
For all code examples, refer to iOS Tracking Android Code Examples
AssetOperationViewController 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 has four outlet properties: createNewAssetBtn, bindAssetBtn, updateAssetBtn, and getAssetInfoBtn. These properties are linked to the corresponding UI elements in the view controller's storyboard.
-
The class has four private variables: assetId, assetName, assetDescription, and assetAttributes. These variables store the asset's ID, name, description, and attributes.
-
The viewDidLoad() method is called when the view controller is first loaded. In this method, the class initializes the AssetTracking shared instance and calls the initView() method to initialize the view controller's user interface.
-
The viewWillAppear() and viewWillDisappear() methods are called when the view controller is about to appear or disappear, respectively. In these methods, the class hides or shows the navigation bar, depending on the view controller's visibility.
-
The initView() method is called to initialize the view controller's user interface. In this method, the class adds target-action listeners to the four buttons to perform the corresponding operations when the buttons are tapped.
-
The createAsset() method creates a new asset with the specified attributes. The method calls the AssetTracking.shared.createAsset() method to make the API request. The method also handles the success and failure cases of the API request.
-
The bindAsset() method binds the asset to the current view controller. The method calls the AssetTracking.shared.bindAsset() method to make the API request. The method also handles the success and failure cases of the API request.
-
The updateAsset() method updates the asset's profile with the specified name and description. The method calls the AssetTracking.shared.updateAsset() method to make the API request. The method also handles the success and failure cases of the API request.
-
The getAssetInfo() method gets the asset's profile. The method calls the AssetTracking.shared.getAssetDetail() method to make the API request. The method also handles the success and failure cases of the API request.
Here is a more detailed explanation of some of the key concepts in the code:
-
AssetTracking: This is a class that provides methods for making API requests to the Asset Tracking API.
-
ToastView: This is a class that displays a short message on the screen.