ZendriveVehicleTagging
@objc(ZDZendriveVehicleTagging)
public class ZendriveVehicleTagging : NSObject
This class manages association and dissociation of vehicles to Zendrive SDK.
-
Associates the vehicle to Zendrive SDK.
After successful association of vehicle information, whenever Zendrive SDK will detect a connection to this bluetooth device while the user is driving, it will include this vehicleId in the tags array of
AnalyzedDriveInfo
.If the user connect to bluetooth of multiple associated vehicles during the drive the latest vehicleId will be used as tag. Maximum of two vehicles can be associated.
Note
The bluetooth device of the associated vehicle needs to be the audio route for some duration of the drive for tagging to happen.
Refer to
ZendriveVehicleTaggingError
to get details on the errors thrown by this method.Example:
let vehicleInfo = VehicleInfo(vehicleId: "vehicleId", bluetoothId: "14:0F:C7:62:F8:9E") try ZendriveVehicleTagging.associateVehicle(vehicleInfo)
Bluetooth stereos in automobiles are primarily classic Bluetooth devices, which might not be discoverable from your app. When you associate the user’s vehicle, ask the user to connect their stereo and play audio. Then, use APIs from AVFoundation framework to determine the current audio route and get the identifier of the device. Start with this code:
if let portDescription = AVAudioSession.sharedInstance().currentRoute.outputs.first { // portDescription.uid will contain a string like "14:0F:C7:62:F8:9E-tacl" or "14:0F:C7:62:F8:9E-tsco". // Trim the suffix to get the MAC address of the device if let bluetoothId = portDescription.uid.components(separatedBy: "-").first { // Send this MAC address as bluetoothId in associateVehicle:error: API. let vehicleInfo = VehicleInfo(vehicleId: "vehicleId", bluetoothId: bluetoothId) try ZendriveVehicleTagging.associateVehicle(vehicleInfo) } }
Declaration
Swift
@objc public static func associateVehicle(_ vehicleInfo: VehicleInfo) throws
Parameters
vehicleInfo
The
VehicleInfo
object to associate. -
Dissociates the vehicle from Zendrive SDK.
After successful dissociation of the vehicle, Zendrive SDK will stop tagging the trips for this vehicle.
Refer to
ZendriveVehicleTaggingError
to get details on the errors thrown by this method.Example:
let vehicleInfo = VehicleInfo(vehicleId: "vehicleId", bluetoothId: "14:0F:C7:62:F8:9E") try ZendriveVehicleTagging.dissociateVehicle(vehicleInfo.vehicleId)
Declaration
Swift
@objc public static func dissociateVehicle(_ vehicleId: String) throws
Parameters
vehicleId
The vehicleId of the vehicle which is to be dissociated.
-
Declaration
Swift
@objc public static func getAssociatedVehicles() -> [VehicleInfo]?
Return Value
- The list of associated vehicles if sdk is setup, else nil.
-
Declaration
Swift
@objc public static func getAssociatedVehicleForDrive(_ driveInfo: DriveInfo) -> String?
Return Value
- The vehicleId if
DriveInfo.tags
array contains the vehicle tag, else nil.