ZendriveVehicleTagging

@interface ZendriveVehicleTagging : NSObject

This class manages association and dissociation of vehicles to ZendriveSDK.

  • Associates the vehicle to ZendriveSDK.

    After successful association of vehicle information, whenever ZendriveSDK will detect a connection to this bluetooth device while the user is driving, it will include this vehicleId in the tags array of ZendriveAnalyzedDriveInfo.

    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:

    NSError *error;
    ZendriveVehicleInfo *vehicleInfo = [[ZendriveVehicleInfo alloc] initWithVehicleId:@"vehicleId" bluetoothId:@"14:0F:C7:62:F8:9E"];
    BOOL success = [ZendriveVehicleTagging associateVehicle:vehicleInfo error:&error];
    

    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:

    ZendriveBluetoothDevice *bluetoothDevice = [ZendriveVehicleTagging getActiveBluetoothDevice];
    if (bluetoothDevice) {
        NSError *error;
        ZendriveVehicleInfo *vehicleInfo = [[ZendriveVehicleInfo alloc] initWithVehicleId:@"vehicleId" bluetoothId:bluetoothDevice.identifier];
        BOOL success = [ZendriveVehicleTagging associateVehicle:vehicleInfo error:&error];
    }
    

    Declaration

    Objective-C

    + (BOOL)associateVehicle:(ZendriveVehicleInfo *_Nonnull)vehicleInfo
                       error:(NSError *_Nullable *_Nullable)error;

    Parameters

    vehicleInfo

    The ZendriveVehicleInfo object to associate.

    error

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

    Return Value

    YES if association is successful, else NO.

  • Dissociates the vehicle from ZendriveSDK.

    After successful dissociation of the vehicle, ZendriveSDK will stop tagging the trips for this vehicle.

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

    Example:

    NSError *error;
    ZendriveVehicleInfo *vehicleInfo = [[ZendriveVehicleInfo alloc] initWithVehicleId:@"vehicleId" bluetoothId:@"14:0F:C7:62:F8:9E"];
    BOOL success = [ZendriveVehicleTagging dissociateVehicle:vehicleInfo.vehicleId error:&error];
    

    Declaration

    Objective-C

    + (BOOL)dissociateVehicle:(NSString *_Nonnull)vehicleId
                        error:(NSError *_Nullable *_Nullable)error;

    Parameters

    vehicleId

    The vehicleId of the vehicle which is to be dissociated.

    error

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

    Return Value

    YES if dissociation is successful, else NO.

  • Declaration

    Objective-C

    + (NSArray<ZendriveVehicleInfo *> *_Nullable)getAssociatedVehicles;

    Return Value

    The list of associated vehicles if sdk is setup, else nil.

  • Declaration

    Objective-C

    + (NSString *_Nullable)getAssociatedVehicleForDrive:
        (ZendriveDriveInfo *_Nonnull)driveInfo;

    Return Value

    The vehicleId if ZendriveDriveInfo.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

    Objective-C

    + (ZendriveBluetoothDevice *_Nullable)getActiveBluetoothDevice;
  • 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 ZendriveAnalyzedDriveInfo.

    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:

    NSError *error;
    ZendriveBeacon *zendriveBeacon = [[ZendriveBeacon alloc] initWithUUIDString:@"FD94C06F-8667-46C2-A334-14C6BF8EDEC3" major:100 minor:100];
    ZendriveVehicleBeacon *zendriveVehicleBeacon = [[ZendriveVehicleBeacon] alloc] initWithVehicleId:@"vehicleId" beacon:zendriveBeacon];
    BOOL success = [ZendriveVehicleTagging associateBeacon:zendriveVehicleBeacon error:&error];
    

    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

    Objective-C

    + (BOOL)associateBeacon:(ZendriveVehicleBeacon *_Nonnull)vehicleBeacon
                      error:(NSError *_Nullable *_Nullable)error;

    Parameters

    vehicleBeacon

    The ZendriveVehicleBeacon object to associate.

    error

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

    Return Value

    YES if association is successful, else NO.

  • Dissociates the beacons corresponding to vehicle from ZendriveSDK.

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

    Example:

    NSError *error;
    BOOL success = [ZendriveVehicleTagging dissociateBeacon:@"vehicleId" error:&error];
    

    Declaration

    Objective-C

    + (BOOL)dissociateBeacon:(NSString *_Nonnull)vehicleId
                       error:(NSError *_Nullable *_Nullable)error;

    Parameters

    vehicleId

    The vehicleId of the vehicle which is to be dissociated.

    error

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

    Return Value

    YES if dissociation is successful, else NO.

  • Declaration

    Objective-C

    + (NSArray<ZendriveVehicleBeacon *> *_Nullable)getAssociatedBeacons;

    Return Value

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

  • Get all the beacons which are in the device’s range using UUID, major, minor.

    Example:

    [ZendriveVehicleTagging getNearbyBeacons:"FD94C06F-8667-46C2-A334-14C6BF8EDEC3" major:100 minor:100 completionHandler: ^{
    ^([ZendriveScannedBeaconInfo] scannedBeaconList, NSError *error) {
      // update scanned beacons list in state or redraw UI
      // user selects a beacon
      // ZendriveScannedBeaconInfo *selectedBeacon;
      // associate beacon using
    ZendriveBeacon *zendriveBeacon = [[ZendriveBeacon alloc] initWithUUIDString:selectedBeacon.uuid major:selectedBeacon.major minor:selectedBeacon.minor];
    ZendriveVehicleBeacon *zendriveVehicleBeacon = [[ZendriveVehicleBeacon] alloc] initWithVehicleId:@"vehicleId" beacon:zendriveBeacon];
    BOOL success = [ZendriveVehicleTagging associateBeacon:zendriveVehicleBeacon error:&error];
    })
    }];
    

    Declaration

    Objective-C

    + (void)getNearbyBeacons:(nonnull NSString *)uuid
                       major:(int)major
                       minor:(int)minor
           completionHandler:
               (nonnull void (^)(NSArray<ZendriveScannedBeaconInfo *> *_Nonnull,
                                 NSError *_Nullable))completionHandler;

    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 using UUID.

    Example:

    [ZendriveVehicleTagging getNearbyBeacons:"FD94C06F-8667-46C2-A334-14C6BF8EDEC3" completionHandler: ^{
    ^([ZendriveScannedBeaconInfo] scannedBeaconList, NSError *error) {
      // update scanned beacons list in state or redraw UI
      // user selects a beacon
      // ZendriveScannedBeaconInfo *selectedBeacon;
      // associate beacon using
    ZendriveBeacon *zendriveBeacon = [[ZendriveBeacon alloc] initWithUUIDString:selectedBeacon.uuid major:selectedBeacon.major minor:selectedBeacon.minor];
    ZendriveVehicleBeacon *zendriveVehicleBeacon = [[ZendriveVehicleBeacon] alloc] initWithVehicleId:@"vehicleId" beacon:zendriveBeacon];
    BOOL success = [ZendriveVehicleTagging associateBeacon:zendriveVehicleBeacon error:&error];
    })
    }];
    

    Declaration

    Objective-C

    + (void)getNearbyBeacons:(nonnull NSString *)uuid
           completionHandler:
               (nonnull void (^)(NSArray<ZendriveScannedBeaconInfo *> *_Nonnull,
                                 NSError *_Nullable))completionHandler;

    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.

  • Declaration

    Objective-C

    + (BOOL)isTaggedByBeacon:(ZendriveDriveInfo *_Nonnull)driveInfo;

    Return Value

    YES if ZendriveDriveInfo.tags array contains the vehicle tag mode as beacon, else NO.

  • Declaration

    Objective-C

    + (BOOL)isTaggedByBluetooth:(ZendriveDriveInfo *_Nonnull)driveInfo;

    Return Value

    YES if ZendriveDriveInfo.tags array contains the vehicle tag mode as bluetooth stereo, else NO.