Implementing Kruzr SDK
You are now ready to start implementing methods within SDK Callbacks!
This section walks you through Trip State call backs. While implementing, it is important that you understand the purpose and function of each of these methods. We would request that please go through our section on Understanding Features & Methods of Kruzr SDK section if you have not already.
All your interactions with the Kruzr SDK will happen through an instance of class Kruzr.
Initializing TripManagerDelegate
TripManagerDelegate
In order to use the various trip states we offer, you will need to create an implementation of TripManagerDelegate
where you will receive callbacks as shown below.
import KruzrTripFramework;
class CompanyTripManager: NSObject, TripManagerDelegate {
func detectedNewTrip() {
print("detected a new trip.")
}
func didTripStarted(status:Int, response:TripSuccessResponse?, error:TripError?) {
if status == 200 {
print("trip has been started successfully: tripId : \(response.tripId)")
}
}
func didStopDriving(tripId:String) {
print("user stops at intermediate stop.")
}
func didResumeDriving(tripId:String) {
print("user started driving again.")
}
func didTripEnd(tripId:String) {
print("trip has been ended successfully.")
}
}
Note: Error Codes for didTripStarted()
-
status
error.message
400
Another trip is still in progress.
400
Give us a moment, we are processing your last trip.
409
Your phone battery is very low.
405
Please provide us location permission.
405
Permissions Missing.Please provide us location and motion both permissions and try again.
401
Authentication Failed.
Initializing the SDK
Initialize the SDK with your SDK_Key
and a DRIVER_ID
which will identify this driver in the system. When Kruzr SDK is set up for the first time, it also requests location access from iOS.
You need to register your users with Kruzr SDK for us to create user specific trip list, profiles and manage scoring. In order register, you will need to create a DRIVER_ID
token which you will need to share with us.
func initializeSDK() {
let kruzrTripManagerDelegate: TripManagerDelegate = CompanyTripManager()
let kruzrConf: KruzrTripFrameworkConfiguration = KruzrTripFrameworkConfiguration()
kruzrConf.licenseKey = "<KRUZR_SDK_KEY>"; // REQUIRED
TripManager.sharedInstance.setup(withConf:kruzrConf,delegate:kruzrTripManagerDelegate) { (success, error) in
If success {
print(“SDK Initialized successfully.”)
} else {
print(“error:\(error)”)
}
}
Note: Calling initializeSDK()
is necessary on every app launch
initializeSDK()
is necessary on every app launchPlease note that initializeSDK()
must be called on every app launch. There are 2 options of doing this within your code:
By calling setup method from
didFinishLaunchingWithOptions
By calling setup method from the
initial view controller
of your application
Once you have created instance of Kruzr SDK and set-up TripManager, you are now ready to register your user and their trips with Kruzr SDK and our back-end. Please continue to next section explore more about Trip Control methods within Kruzr SDK and how you can use them in your iOS App!
Last updated
Was this helpful?