Zendrive
@objc(ZDZendrive)
public final class Zendrive : NSObject
Zendrive Object.
-
Zendrive SDK version
Declaration
Swift
@objc public static let zendriveSDKVersion: String
-
Identifier used by
Zendrive
SDK for region monitoring geofencesDeclaration
Swift
@objc public static let zendriveGeofenceIdentifier: String
-
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
false
whenever setup fails and sets up the error with the error code, cause and description.Things to Consider:-
- To change the
Configuration.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 SDK is setup or not. - If
Configuration.driverId
orConfiguration.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
Swift
@objc public static func setup(with configuration: Configuration, delegate: ZendriveDelegate?, completionHandler handler: ((_ success: Bool, _ error: Error?) -> Void)? = nil)
Parameters
configuration
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
-
Set delegate to receive callbacks for various events from Zendrive SDK. See
ZendriveDelegate
for further details.Calling this if Zendrive is not setup is a no-op.
See also
setup(with:delegate:completionHandler:)
for further details.This is a convenience method that can be used in addition to the
setup(with:delegate:completionHandler:)
method to easily setup the Zendrive SDK. This method sets up the Zendrive SDK using theConfiguration
that was provided to thesetup(with:delegate:completionHandler:)
method last time. Call this method from theUIApplicationDelegate.applicationDidBecomeActive(_:)
method. Make sure you provide the sameZendriveDelegate
reference to both the resume and setup methods.Declaration
Swift
@objc public static func resume(delegate: ZendriveDelegate?, completionHandler handler: ((_ success: Bool, _ error: Error?) -> Void)? = nil)
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.
- handler : This block is called when zendrive setup. The application is expected to use the success and params passed to this block to handle failures. The handler would be invoked on the main thread. Can be nil.
handler
This block is called when zendrive setup. The application is expected to use the success and params passed to this block to handle failures. The handler would be invoked on the main thread. Can be nil.
-
This method is to update the existing
ZendriveDelegate
on which Zendrive SDK will issue callbacks for handling various events.Declaration
Swift
@objc public static func setDelegate(_ delegate: ZendriveDelegate?)
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 drive detection mode controls how Zendrive SDK detects drives. See
DriveDetectionMode
for further details.Use this method to get the current
DriveDetectionMode
.Declaration
Swift
@objc public static func getDriveDetectionMode() -> DriveDetectionMode
-
Change the drive detection mode to control how Zendrive SDK detects drives. See
DriveDetectionMode
for further details. This will override the mode sent withConfiguration
during setup.Calling this method stops an ongoing auto-detected drive. If the SDK is not setup calling this method will result in a no-op.
Declaration
Swift
@objc public static func setDriveDetectionMode(_ driveDetectionMode: DriveDetectionMode, completionHandler: ((_ success: Bool, _ error: Error?) -> Void)? = nil)
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: success, A boolean that suggests if drive is started successfully error, A valid error
ZendriveError
object withzendriveErrorDomain
is returned in case of a failure. Possible error codes returned:ZendriveError.notSetup
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
setup(with: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
Swift
@objc public static func teardown(completionHandler handler: (() -> Void)? = nil)
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
teardown(completionHandler:)
to tear down a live SDK before making this call.Declaration
Swift
@objc public static func wipeOut() throws
-
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(_:)
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
setup(with:delegate:completionHandler:)
is a no-op.Calling
startManualDrive(_:completionHandler:)
with the same trackingId without callingstopManualDrive(_:)
in between is a no-op. CallingstartManualDrive(_:completionHandler:)
with a different trackingId: with implicitly call stopManualDrive(_:) before starting a new drive.This is an asynchronous method,
ZendriveDelegate.processStart(ofDrive:)
is triggered once this finishes with basic information about the driveactiveDriveInfo
will return nil untilZendriveDelegate.processStart(ofDrive:)
is calledSee also
You need to call
stopManualDrive(_:)
to stop drive data collection.Declaration
Swift
@objc public static func startManualDrive(_ trackingId: String?, completionHandler: ((_ success: Bool, _ error: Error?) -> Void)? = nil)
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
is returned in case of a failure. Possible error codes returned:ZendriveError.notSetup
,ZendriveError.invalidTrackingId
Refer toZendriveError
for more details on the errors. -
Logs all the critical permission required by the SDK
Declaration
Swift
@objc public static func logSDKHealth(_ reason: ZendriveSDKHealthReason, completionHandler: @escaping (Error?) -> Void)
Parameters
sdkHealthReason
indicates the reason for logging SDK Health
-
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
is returned in case of a failure. Possible error codes returned:ZendriveError.notSetup
,ZendriveError.invalidTrackingId
,ZendriveError.internalFailure
. Refer toZendriveError
for more details on the errors. success, A boolean that suggests if drive is stopped successfullyCalling it without having initialized the Zendrive SDK is a no-op.
Declaration
Swift
@objc public static func stopManualDrive(_ completionHandler: ((_ success: Bool, _ error: Error?) -> Void)? = nil)
-
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
Swift
@objc public static func startSession(_ sessionId: String)
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 also
startSession(_:)
Declaration
Swift
@objc public static func 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- “?”, “ ”, “&”, “/”, “\”, “;”, “#” Non-ascii characters are not allowed.
Declaration
Swift
@objc public static func isValidInputParameter(_ input: String?) -> Bool
Parameters
input
The string to validate.
Return Value
true
if the string isnil
or valid,false
otherwise. -
Returns
true
if the Zendrive SDK is already setup. Elsefalse
.Declaration
Swift
@objc public static var isSDKSetup: Bool { get }
-
Returns an identifier which can be used to identify this SDK build.
Declaration
Swift
@objc public static var buildVersion: String { get }
-
Get info on the currently active drive. If sdk is not setup or if no drive is in progress, nil is returned.
Declaration
Swift
@objc public static var activeDriveInfo: ActiveDriveInfo? { get }
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
ZendriveDelegate.processAnalysis(ofDrive:)
is called. If called before or at a later point in time, the drive type returned is.invalid
.Declaration
Swift
@objc public static func getInternalDriveType(forTimestamp timestamp: Int64) -> InternalDriveTypePreview
-
Get the current state of the Zendrive SDK.
Declaration
Swift
@objc public static func getState(_ completionHandler: ((State?) -> Void)? = nil)
Parameters
completionHandler
A block object to be executed when the task finishes. This block has no return value and a single argument: state, A Zendrive
State
object that informs about the current state of the sdk. If the SDK is not set up, the state is nil. -
Returns a boolean indicating whether Zendrive SDK can detect accidents on this devices or not.
Declaration
Swift
@objc public static var isAccidentDetectionSupportedByDevice: Bool { get }
-
Returns a NSDictionary with keys as
EventType
and values being Bool which represent if a particular event will be detected by the SDK on this device.Declaration
Swift
@objc public static var getEventSupportForDevice: [AnyHashable : Any] { get }
-
Send a debug report of the current driver to Zendrive. The Zendrive SDK will create a background task to ensure the completion of this upload task.
Declaration
Swift
@objc public static func uploadAllDebugDataAndLogs()
-
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:
let pausedTillTimestamp = 1634014320000; try Zendrive.pauseAutoTracking(pausedTillTimestamp);
Declaration
Swift
@objc public static func pauseAutoTracking(_ pausedTillTimestamp: Int64) throws
-
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:
try Zendrive.resumeAutoTracking;
Declaration
Swift
@objc public static func resumeAutoTracking() throws
-
After success of isAutoTrackingPaused request, it will return the current status of SDK’s auto tracking. The return bool is wrapped in a NSNumber for objective-c compatibility.
Refer to
ZendriveError
to get details on the errors thrown by this method.Example:
try Zendrive.isAutoTrackingPaused().boolValue;
Declaration
Swift
@objc public static func isAutoTrackingPaused() throws -> NSNumber
-
Returns the reason for the SDK being paused. throws:
ZendriveError.notSetup
Example:
do { let pausedReason = try Zendrive.getPausedReason() switch (pausedReason.pausedReason) { } catch { // handle error. }
Declaration
Swift
public static func getPausedReason() throws -> PausedReason
Return Value
PausedReason encapsulating ZendrivePausedReasonEnum with values.
- .user: The SDK is paused manually by user.
- .businessHours: The SDK is paused automatically due to business hours.
- .notPaused: The SDK is not paused.
-
Instantly Refreshes the business hours, the SDK makes an API call to the backend to fetch the latest business hours.
Declaration
Swift
@objc public static func refreshBusinessHours(completionHandler: @escaping (_ businessHours: ShiftDetail?, _ error: NSError?) -> Void)