Zendrive
@objc(ZDZendrive)
public final class Zendrive : NSObject
Zendrive Object.
-
Identifier used by
Zendrive
SDK for region monitoring geofencesDeclaration
Swift
@objc public 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 authenticates the configuration with the server asynchronously before returning status.
Calling this method multiple times with the same values for applicationKey and driverId pair is a no-op. Changing either will be the same as calling teardown followed by calling setup with the new parameters. Please note that even if other configuration parameters like driverAttributes or driveDetectionMode are changed, but driverId and applicationKey remain same, calling this method would still be a no-op. If you want to change these configuration parameters, invoke teardown explicitly and call this method again with the new configuration.
This method requires network connection for every time the setup is called with a different value for applicationKey, driverId pair to validate the applicationKey from the server. Setup fails and returns
false
if network is not available in such cases.This method returns
false
whenever setup fails and sets up the error with the error code, cause and description.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.
-
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.Declaration
Swift
@objc public static func setDelegate(_ delegate: ZendriveDelegate?)
Parameters
delegate
The delegate object to give callbacks on.
-
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. -
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 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()