Zendrive
@interface Zendrive : NSObject
Zendrive Object.
-
Initializes the Zendrive library to automatically detect driving and collect data. Client code should call this method before anything else in the Zendrive API.
This method requires network connection to validate the applicationKey from the server. Setup fails and returns NO if network is not available.
This method returns NO whenever setup fails and sets up the error with the error code, cause and description.
Things to Consider:-
- To change the
ZendriveConfiguration.region
, you need to call+wipeOut:
first. - If you are doing multiple setups, i.e calling this API multiple times and the newer setup fails,
then the SDK may continue working according to parameters provided in older setup or it may
get torndown. In all such cases please check
+isSDKSetup
in the completion handler to confirm if the SDK is setup or not. - If
ZendriveConfiguration.driverId
orZendriveConfiguration.applicationKey
is changed while doing multiple setups, it will be the same as calling teardown followed by calling setup with the new parameters.
When data collection needs to be stopped call the teardown method. This might be done for example when the application’s user has logged out (and possibly a different user might login later).
Declaration
Objective-C
+ (void)setupWithConfiguration: (nonnull ZendriveConfiguration *)zendriveConfiguration delegate:(nullable id<ZendriveDelegateProtocol>)delegate completionHandler:(nullable ZendriveApiCallHandler)handler;
Parameters
zendriveConfiguration
The configuration object used to setup the SDK. This object contains your credentials along with additional setup parameters that you can use to provide meta-information about the user or to tune the sdk functionality.
delegate
The delegate object on which Zendrive SDK will issue callbacks for handling various events. Can be nil if you do not want to register for callbacks. The delegate can also be set at a later point using
+setDelegate:
method.handler
This block is called when zendrive setup completes. The application is expected to use the success and error params passed to this block to handle failures. The handler would be invoked on the main thread. Can be nil.
- To change the
-
This is a convenience method that can be used in addition to the
+setupWithConfiguration:delegate:completionHandler:
method to easily setup the Zendrive SDK. This method sets up the Zendrive SDK using theZendriveConfiguration
that was provided to the+setupWithConfiguration:delegate:completionHandler:
method last time. Call this method from the-[UIApplicationDelegate applicationDidBecomeActive:]
method. Make sure you provide the sameZendriveDelegateProtocol
reference to both the resume and setup methods.Declaration
Objective-C
+ (void)resumeWithDelegate:(nullable id<ZendriveDelegateProtocol>)delegate completionHandler:(nullable ZendriveApiCallHandler)handler;
Parameters
delegate
The delegate object on which Zendrive SDK will issue callbacks for handling various events. Can be nil if you do not want to register for callbacks. The delegate can also be set at a later point using
+setDelegate:
method.handler
This block is called when zendrive setup completes. The application is expected to use the success and error params passed to this block to handle failures. The handler would be invoked on the main thread. Can be nil.
-
Set delegate to receive callbacks for various events from Zendrive SDK. See
ZendriveDelegateProtocol
for further details.Calling this if Zendrive is not setup is a no-op.
See
+setupWithConfiguration:delegate:completionHandler:
for further details.Declaration
Objective-C
+ (void)setDelegate:(nullable id<ZendriveDelegateProtocol>)delegate;
Parameters
delegate
The delegate object to give callbacks on.
-
The drive detection mode controls how Zendrive SDK detects drives. See
ZendriveDriveDetectionMode
for further details.Use this method to get the current
ZendriveDriveDetectionMode
.Declaration
Objective-C
+ (ZendriveDriveDetectionMode)getDriveDetectionMode;
-
Change the drive detection mode to control how Zendrive SDK detects drives. See
ZendriveDriveDetectionMode
for further details. This will override the mode sent withZendriveConfiguration
during setup.Calling this method stops an ongoing auto-detected drive. Calling this method when the SDK is not setup is a no-op.
Declaration
Objective-C
+ (void)setDriveDetectionMode:(ZendriveDriveDetectionMode)driveDetectionMode completionHandler: (nullable ZendriveApiCallHandler)completionHandler;
Parameters
driveDetectionMode
The new drive detection mode.
completionHandler
A block object to be executed when the task finishes. This block has no return value and two arguments: isSuccess, A boolean that suggests if drive is started successfully error, A valid error of
ZendriveErrorDomain.kZendriveErrorDomain
(ZendriveError
) is returned in case of a failure. Possible error codes returned: kZendriveErrorNotSetup Refer to ZendriveError for more details on the errors. -
Stops driving data collection. The application can disable the Zendrive SDK by invoking this method. This method is asynchronous.
The teardown method is internally synchronized with
+setupWithConfiguration:delegate:completionHandler:
method, and the enclosing application should avoid synchronizing the two methods independently. Calling this with nil completion handler is same as calling teardown method.Declaration
Objective-C
+ (void)teardownWithCompletionHandler:(void (^_Nullable)(void))handler;
Parameters
handler
Called when method completes. The handler would be invoked on main thread. Can be nil.
-
Wipe out all the data that zendrive keeps locally on the device.
When Zendrive SDK is torn down, trip data that is locally persisted continues to remain persisted. The data will be uploaded when SDK setup is called at a later time. Wipeout should be used when the application wants to remove all traces of Zendrive on the device. Data cannot be recovered after this call. NOTE: This call can only be made when the SDK is not running. Call
+teardownWithCompletionHandler:
to tear down a live SDK before making this call.Declaration
Objective-C
+ (BOOL)wipeOut:(NSError *_Nullable *_Nullable)error;
-
This API allows application to override Zendrive’s auto drive detection algorithm.
Invoking this method forces the start of a drive. If this API is used then it is application’s responsibility to terminate the drive by invoking stopManualDrive:completionHandler: method. If an auto-detected drive is in progress, that drive is stopped and a new drive is started.
These methods should be used only by applications which have explicit knowledge of start and end of drives and want to attribute drive data to specific trackingIds.
Calling it without having initialized the Zendrive framework (setupWithApplicationId) is a no-op.
Calling startManualDrive:completionHandler: with the same trackingId without calling stopManualDrive:completionHandler: in between is a no-op. Calling startManualDrive:completionHandler: with a different trackingId: with implicitly call stopManualDrive:completionHandler: before starting a new drive.
This is an asynchronous method,
-[ZendriveDelegateProtocol processStartOfDrive:]
is triggered once this finishes with basic information about the drive+activeDriveInfo
will return nil untilprocessStartOfDrive:
is calledSee
+stopManualDrive:completionHandler:
You need to call
+stopManualDrive:completionHandler:
to stop drive data collection.Declaration
Objective-C
+ (void)startManualDrive:(nullable NSString *)trackingId completionHandler:(nullable ZendriveApiCallHandler)completionHandler;
Parameters
completionHandler
A block object to be executed when the task finishes. This block has no return value and two arguments: isSuccess, A boolean that suggests if drive is started successfully error, A valid error of
ZendriveErrorDomain.kZendriveErrorDomain
(ZendriveError
) is returned in case of a failure. Possible error codes returned: kZendriveErrorNotSetup, kZendriveErrorInvalidTrackingId Refer to ZendriveError for more details on the errors. -
This should be called to indicate the end of a drive started by invoking
+startManualDrive:completionHandler:
This block has no return value and two arguments: the error, A valid error of
ZendriveErrorDomain.kZendriveErrorDomain
(ZendriveError
) is returned in case of a failure. Possible error codes returned: kZendriveErrorNotSetup, kZendriveErrorInvalidTrackingId, kZendriveErrorInternalFailure. Refer to ZendriveError for more details on the errors. isSuccess, A boolean that suggests if drive is stopped successfullyCalling it without having initialized the Zendrive SDK is a no-op.
Declaration
Objective-C
+ (void)stopManualDrive:(nullable ZendriveApiCallHandler)completionHandler;
-
Start a session in the SDK.
Applications which want to record several user’s drives as a session may use this call.
All drives, either automatically detected or started using
+startManualDrive:completionHandler:
, will be tagged with the sessionId if a session is already in progress. If a drive is already on when this call is made, that drive will not belong to this session.This session id will be made available as a query parameter in the reports and API that Zendrive provides.
The application must call
+stopSession
when it wants to end the session.Only one session may be active at a time. Calling startSession when a session is already active with a new sessionId will stop the ongoing session and start a new one.
Calling it without having initialized the Zendrive SDK is a no-op.
Declaration
Objective-C
+ (void)startSession:(nonnull NSString *)sessionId;
Parameters
sessionId
an identifier that identifies this session uniquely. Cannot be null or an empty string. Cannot be longer than 64 characters. Use
+isValidInputParameter:
to verify that groupId is valid. Passing invalid string is a no-op. -
Stop currently ongoing session. No-op if no session is ongoing. Trips that start after this call do not belong to the session. Ongoing trips at the time of this call will continue to belong to the session that was just stopped.
See
+startSession:
Declaration
Objective-C
+ (void)stopSession;
-
Use this method to check whether the parameter string passed to the SDK is valid.
All strings passed as input params to Zendrive SDK cannot contain the following characters- “?”, “ ”, “&”, “/”, “\”, “;”, “#”, “\n”. Non-utf8 characters are not allowed.
Declaration
Objective-C
+ (BOOL)isValidInputParameter:(nullable NSString *)input;
Parameters
input
The string to validate.
Return Value
YES if the string is nil or valid, NO otherwise.
-
Is the Zendrive SDK already setup?
Declaration
Objective-C
+ (BOOL)isSDKSetup;
Return Value
YES if Zendrive SDK is already setup. Else NO.
-
Declaration
Objective-C
+ (nonnull NSString *)buildVersion;
Return Value
An identifier which can be used to identify this SDK build.
-
Get info on the currently active drive. If sdk is not setup or if no drive is in progress, nil is returned.
Declaration
Objective-C
+ (nullable ZendriveActiveDriveInfo *)activeDriveInfo;
Return Value
The currently active drive information.
-
Get the internal drive type for a given drive. This is a preview API and its usage should be restricted to experimental purpose.
NOTE: This API should be called when the
ZendriveDelegateProtocol.processAnalysisOfDrive
is called. If called before or at a later point in time, the drive type returned isZendriveInternalDriveTypePreviewInvalid
.Declaration
Objective-C
+ (ZendriveInternalDriveTypePreview)getInternalDriveTypeForTimestamp: (long long)timestamp;
Parameters
timestamp
of the drive which is
ZendriveDriveInfo.startTimestamp
Return Value
internal drive type enum
-
Logs all the critical permission required by the SDK
Declaration
Objective-C
+ (void)logSDKHealth:(ZendriveSDKHealthReason)sdkHealthReason error:(void (^_Nonnull)(NSError *_Nullable))completionHandler;
Parameters
sdkHealthReason
indicates the reason for logging SDK Health
completionHandler
The error pointer where ZendriveSDK will populate the error thrown by the method. mainly when sdk is not setup
-
Get the current state of the Zendrive SDK.
Declaration
Objective-C
+ (void)getZendriveState: (void (^_Nullable)(ZendriveState *_Nullable))completionHandler;
Parameters
completionHandler
A block object to be executed when the task finishes. This block has no return value and a single argument: zendriveState, A
ZendriveState
object that informs about the current state of the sdk. If the SDK is not set up, the zendriveState is nil. -
Declaration
Objective-C
+ (BOOL)isAccidentDetectionSupportedByDevice;
Return Value
A boolean indicating whether ZendriveSDK can detect accidents on this devices or not.
-
Returns a NSDictionary with keys as
ZendriveEventType
and values being BOOL which represent if a particular event will be detected by the SDK on this device.Declaration
Objective-C
+ (nonnull NSDictionary *)getEventSupportForDevice;
-
Send a debug report of the current driver to Zendrive. The ZendriveSDK will create a background task to ensure the completion of this upload task.
Declaration
Objective-C
+ (void)uploadAllDebugDataAndLogs;
-
Declaration
Objective-C
+ (ZendriveSettings *_Nullable)getZendriveSettings;
Return Value
A valid
ZendriveSettings
object if the SDK is setup, otherwise nil. -
After success of pauseAutoTracking request, automatic trip detection by the SDK will be paused till pausedTillTimestamp which will be provided as part of the parameter.
Refer to
ZendriveError
to get details on the errors thrown by this method.Example:
NSError *error; long long pausedTillTimestamp = 1634014320000; BOOL success = [Zendrive pauseAutoTracking:pausedTillTimestamp error:&error];
Declaration
Objective-C
+ (BOOL)pauseAutoTracking:(long long)pausedTillTimestamp error:(NSError *_Nullable *_Nullable)error;
Parameters
pausedTillTimestamp
- till the pausedTillTimestamp auto tracking will be paused
error
The error pointer where ZendriveSDK will populate the error thrown by the method.
Return Value
YES if pauseAutoTracking is successful, else NO.
-
After success of resumeAutoTracking request, auto tracking of the SDK will be resumed right away.
Refer to
ZendriveError
to get details on the errors thrown by this method.Example:
NSError *error; BOOL success = [Zendrive resumeAutoTracking:&error];
Declaration
Objective-C
+ (BOOL)resumeAutoTracking:(NSError *_Nullable *_Nullable)error;
Parameters
error
The error pointer where ZendriveSDK will populate the error thrown by the method.
Return Value
YES if resumeAutoTracking is successful, else NO.
-
After success of isAutoTrackingPaused request, it will return the current status of SDK’s auto tracking.
Refer to
ZendriveError
to get details on the errors thrown by this method.Example:
NSError *error; BOOL success = [[Zendrive isAutoTrackingPaused:&error] boolValue];
Declaration
Objective-C
+ (nullable NSNumber *)isAutoTrackingPaused: (NSError *_Nullable *_Nullable)error;
Parameters
error
The error pointer where ZendriveSDK will populate the error thrown by the method.
Return Value
nil if SDK throws any error
-
Returns the reason for the SDK being paused.
Refer to
ZendriveError
to get details on the errors thrown by this method.Example:
NSError *error; ZendrivePausedReason *pausedReason = [Zendrive getPausedReason:&error]; if (error != nil) { // handle the error } else { ZendrivePausedResasonEnum pausedReasonEnum = pausedReason.pausedReason }
Declaration
Objective-C
+ (ZendrivePausedReason *_Nullable)getPausedReason: (NSError *_Nullable *_Nullable)error;
Parameters
error
The error pointer where ZendriveSDK will populate the error thrown by the method. throws ZendriveError.
Return Value
nil if SDK throws any error
-
Refreshes the business hours, the SDK makes an API call to the backend to fetch the latest business hours set by the fleet manager..
Declaration
Objective-C
+ (void)refreshBusinessHours: (void (^_Nonnull)(ZendriveShiftDetail *_Nullable, NSError *_Nullable))completionHandler;
Parameters
completionHandler
A block object to be executed when the task finishes. This block has no return value and two arguments: shiftDetails, A nullable ZendriveShiftDetail object which provide the business hours. error, A valid error of
ZendriveErrorDomain.kZendriveErrorDomain
(ZendriveError
) is returned in case of a failure. Possible error codes returned: kZendriveErrorRefreshBusinessHoursTimeout,kZendriveErrorNotSetup, kZendriveErrorRefreshBusinessHoursNetworkNotAvailable, kZendriveErrorRefreshBusinessHoursNotEnabled error. Refer to ZendriveError for more details on the errors. Example:NSError *error; [Zendrive refreshBusinessHours:completionHandler:&error];