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 getActiveBluetoothDevice() to determine the active bluetooth connection and get the identifier of the device. Start with this code:

     if let bluetoothDevice = ZendriveVehicleTagging.getActiveBluetoothDevice() {
        let vehicleInfo = VehicleInfo(vehicleId: "vehicleId",
                                      bluetoothId: bluetoothDevice.identifier)
        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.

  • Returns the active bluetooth device, if there is any, otherwise returns nil.

    The active bluetooth device is the one through which audio will play. Example: You may be connected to both car’s stereo and airpods but only one of them will be active, the one through which audio is playing or will play.

    Note

    If the user does not have multiple connected audio devices like headphones, airpods etc, then the connected car’s stereo is the active device.

    Declaration

    Swift

    @objc
    public static func getActiveBluetoothDevice() -> BluetoothDevice?
  • Associates the vehicle beacon to ZendriveSDK.

    After successful association of vehicle beacon information, whenever ZendriveSDK will detect a connection to this beacon while the user is driving, it will include this vehicleId and tag mode in the tags array of AnalyzedDriveInfo.

    If the user connects to beacons of multiple associated vehicles during the drive the latest vehicleId will be used as tag. Maximum of two vehicles can be associated.

    Refer to ZendriveVehicleTaggingError to get details on the errors thrown by this method.

    Example:

    let beacon: Beacon = Beacon(UUIDString: "FD94C06F-8667-46C2-A334-14C6BF8EDEC3", major: 100, minor: 100)
    let vehicleBeacon: VehicleBeacon = VehicleBeacon(vehicleId: "vehicleId", beacon: beacon)
    try ZendriveVehicleTagging.associateBeacon(beacon)
    

    Use getNearbyBeacons(uuid:major:minor:completionHandler:) to determine the active beacon devices and get the UUID, major, minor of the selected device. Use the selected device’s UUID, major, minor as arguments to associateBeacon(_:) method.

    Declaration

    Swift

    @objc
    public static func associateBeacon(_ vehicleBeacon: VehicleBeacon) throws

    Parameters

    vehicleBeacon

    The VehicleBeacon object to associate.

    error

    The error pointer where ZendriveSDK will populate the error thrown by the method.

  • Dissociates the beacons corresponding to vehicle from ZendriveSDK.

    Refer to ZendriveVehicleTaggingError to get details on the errors thrown by this method.

    Example:

    try ZendriveVehicleTagging.dissociateBeacon("vehicleId")
    

    Declaration

    Swift

    @objc
    public static func dissociateBeacon(_ vehicleId: String) throws

    Parameters

    vehicleId

    The vehicleId of the vehicle which is to be dissociated.

  • Declaration

    Swift

    @objc
    public static func getAssociatedBeacons() -> [VehicleBeacon]?

    Return Value

    - The list of associated vehicle beacons if sdk is setup, else nil.

  • Declaration

    Swift

    @objc
    public static func isTaggedByBeacon(_ driveInfo: DriveInfo) -> Bool

    Return Value

    - true if DriveInfo.tags array contains the vehicle tag mode as beacon, else false.

  • Declaration

    Swift

    @objc
    public static func isTaggedByBluetooth(_ driveInfo: DriveInfo) -> Bool

    Return Value

    - true if DriveInfo.tags array contains the vehicle tag mode as bluetoothStereo, else false.

  • Get all the beacons which are in the device’s range.

    Example:

    ZendriveVehicleTagging.getNearbyBeacons(uuid: "FD94C06F-8667-46C2-A334-14C6BF8EDEC3",
     major: 100,
     minor: 100,
     completionHandler: { (beaconsList: [ZendriveScannedBeaconInfo], error:  NSError?) -> Void in
         if let error = error {
             // handle the error
         }
        // update scanned beacons list in state or redraw UI
        // ScannedBeaconInfo *selectedBeacon;
        // associate beacon using
        let beacon: Beacon = Beacon(UUIDString: "FD94C06F-8667-46C2-A334-14C6BF8EDEC3", major: 100, minor: 100)
        let vehicleBeacon: VehicleBeacon = VehicleBeacon(vehicleId: "vehicleId", beacon: beacon)
        try ZendriveVehicleTagging.associateBeacon(beacon)
        })
    

    Declaration

    Swift

    @objc
    public static func getNearbyBeacons(uuid: String,
                                        major: Int32,
                                        minor: Int32,
                                        completionHandler: @escaping (_ scannedBeacons: [ScannedBeaconInfo], _ error: Error?) -> Void)

    Parameters

    uuid

    The UUID of the beacons that are to be scanned.

    major

    The major of the beacons that are to be scanned.

    minor

    The minor of the beacons that are to be scanned.

    completionHandler

    The completion handler which is to be executed after the completion of beacon scan.

  • Get all the beacons which are in the device’s range.

    Example:

    ZendriveVehicleTagging.getNearbyBeacons(uuid: "FD94C06F-8667-46C2-A334-14C6BF8EDEC3",
     completionHandler: { (beaconsList: [ZendriveScannedBeaconInfo], error:  NSError?) -> Void in
         if let error = error {
             // handle the error
         }
        // update scanned beacons list in state or redraw UI
        // ScannedBeaconInfo *selectedBeacon;
        // associate beacon using
        let beacon: Beacon = Beacon(UUIDString: "FD94C06F-8667-46C2-A334-14C6BF8EDEC3", major: 100, minor: 100)
        let vehicleBeacon: VehicleBeacon = VehicleBeacon(vehicleId: "vehicleId", beacon: beacon)
        try ZendriveVehicleTagging.associateBeacon(beacon)
        })
    

    Declaration

    Swift

    @objc
    public static func getNearbyBeacons(uuid: String,
                                        completionHandler: @escaping (_ scannedBeacons: [ScannedBeaconInfo], _ error: Error?) -> Void)

    Parameters

    uuid

    The UUID of the beacons that are to be scanned.

    completionHandler

    The completion handler which is to be executed after the completion of beacon scan.