2.0.2 • Published 5 days ago

@react-native-drivekit/core v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

@react-native-drivekit/core

React Native interface for DriveKit Core

Installation

Install the library:

npm install @react-native-drivekit/core

Install iOS pods:

cd ios && pod install

Initialization

Android setup

Add DriveQuant Maven repository in your build.gradle.

allprojects {
    repositories {
        maven {
            url "https://maven.drivequant.com/repository/android-sdk/"
        }
    }
}

If you have disabled the DriveKit auto-initialization, call initialize method inside your MainApplication.java.

// MainApplication.java
import com.reactnativedrivekitcore.DriveKitCoreModule;

// ...

  @Override
  public void onCreate() {
    super.onCreate();
    DriveKitCoreModule.Companion.initialize(this);
    // ...
  }

iOS setup

If you have disabled the DriveKit auto-initialization, call initialize method in your AppDelegate.mm.

// AppDelegate.mm
#import <RNDriveKitCore/react-native-drivekit-core-umbrella.h>

// ...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [RNDriveKitCoreWrapper.shared initialize];
  ...
}

Note: If you are using Swift, initialize method is also available.


Permissions

Our recommandation is to use react-native-permissions. You can find an implementation example in the demo application inside this repository.

For location permission, please use requestIOSLocationPermission() method for iOS.

Bluetooth authorization

Even if your app do not use Bluetooth, you MUST include usage description on iOS side. For more details, please take a look inside the native documentation


Common

To finish the module's initialization, you need to :

  1. Specify your API key;
  2. Identify the driver with a unique ID.

Specify your API key

setApiKey(key: string): Promise<void>

Specify your user ID

setUserId(userId: string): Promise<void>

Validation

To validate that the initialization has been done successfully, please check your native logs and verify that you can see the following success message.

Android npm.io

iOS npm.io


Listeners

You can listen to events thanks to the addEventListener api.

useEffect(() => {
  const listener = DriveKit.addEventListener(
    'driveKitDidReceiveAuthenticationError',
    (error: RequestError) => {
      console.log('Received authentication error from DriveKit', error);
    }
  );
  return () => listener.remove();
});

DriveKit related events

Here is the list of supported events:

  • driveKitConnected, callback () => void: This event is triggered when the user has been successfully logged.
  • driveKitDisconnected, callback () => void: This event is triggered when the user has been disconnected.
  • driveKitDidReceiveAuthenticationError, callback (requestError: RequestError) => void: This event is triggered when The login has failed due to a RequestError.
  • accountDeletionCompleted, callback (status: DeleteAccountStatus): This event is triggered when the delete account request has been processed with a DeleteAccountStatus state value.
  • userIdUpdateStatusChanged, callback (status: UpdateUserIdStatus, userId: String?) => void: This event is triggered when the update userId request has been processed with a UpdateUserIdStatus state value.

Device configuration related event

  • deviceConfigurationChanged, callback (event: DeviceConfigurationEvent) => void: This event is triggered when the user disables the sensors or revokes permissions. The list of possible device configuration events is available on native documentation for Android and for iOS.

API

MethodReturn TypeiOSAndroid
getApiKey()Promise<string>
setApiKey()Promise<void>
getUserId()Promise<string>
setUserId()Promise<void>
updateUserId()Promise<void>
deleteAccount()Promise<void>
reset()Promise<void>
enableLogging()Promise<void>
disableLogging()Promise<void>
getUriLogFile()Promise<{ uri: string } \| null>
composeDiagnosisMail()Promise<void>
isTokenValid()Promise<boolean>
getUserInfo()Promise<UserInfo \| null>
updateUserInfo()Promise<void>
requestIOSLocationPermission()Promise<void>-

getApiKey

getApiKey(): Promise<string>

This method can be useful to check which DriveKit API Key you have set in the SDK.

const apiKey = await getApiKey();

setApiKey

setApiKey(key: string): Promise<void>

To use DriveKit modules, you have to obtain an API Key from DriveQuant. If you don't have an API key, please contact DriveQuant.

Once you've stored your API key in a secure way in your application, you can configure DriveKit by calling the following method:

setApiKey('MyAPIKey');

getUserId

getUserId(): Promise<string>

This method can be useful to retrieve the current userId.

const userId = await getUserId();

setUserId

setUserId(userId: string): Promise<void>

Each driver must be identified with a unique identifier. Once you have this identifier, configure DriveKit by calling the following method:

setUserId('MyUserId');

ℹ️

You can call these 2 configuration methods anywhere in the code. DriveKit will save the value locally. If the app is killed and relaunched, DriveKit will be reconfigured automatically.

⚠️

We recommend never using an email address or phone number to define the unique user ID. It is recommended that you set up a unique, universal and anonymous user ID. For example, you can generate a globally unique identifier (GUID) for each of your users.

⚠️

DriveKit SDK will not work until you set the API key and the userId.

updateUserId

updateUserId(userId: string): Promise<void>

It is possible to update the userId by calling the following method:

updateUserId('newUserId');

deleteAccount

deleteAccount(instantDeletion?: boolean): Promise<void>

You can delete a driver's account in DriveKit. This action deletes all the data related to the account.

The deletion can be done instantly or with delay.

  • In the first case, when the method is called, the account is instantly deleted.
  • In the second case, the driver has 30 days to log back into the application and reactivate his account.

To delete a driver's account, use the following method:

deleteAccount(false);

instantDeletion can have 2 values:

  • false : Default value, allows the user to recover the deleted account by logging-in again with the same credentials. Users have 30 days starting from the day when the account was deleted.
  • true : Allows to delete an account instantly. The account and all the related data will be immediately deleted and no rollback is possible.

ℹ️

Your team needs to have the deletion feature activated to use this method. Please contact DriveQuant if you need it.

ℹ️

To be able to check whenever the account deletion is complete, you have to use the DriveKitDelegate interface.

⚠️

You should restore the DriveKit API key in the onAccountDeleted() callback only when the status value is SUCCESS.

reset

reset(): Promise<void>

If you need to reset DriveKit configuration (user logout for example), you can call the following method:

reset();

All data saved locally will be erased and default configuration for every module will be restored.

ℹ️

All DriverKit frameworks have reset method that erases all data saved locally by the framework.

⚠️

Make sure that you call reset method of all frameworks to fully reset DriveKit configuration.

Logging

  enableLogging(options?: { logPath?: string; showInConsole?: boolean }): Promise<void>;

  disableLogging(options?: { showInConsole?: boolean }): Promise<void>;
OptionDefault ValueDescription
showInConsole?: booleantrueset to false if you don't want your logs to be displayed in the console
logPath?: string"/DriveKit"android only - path where the log files will be saved

DriveKit comes with a logging feature that is enabled by default. This feature allows you to quickly identify the cause of a problem. We recommend leaving the log enabled as it does not consume memory space and is useful in the support phase. However, if you don't want to use it, it can be disabled.

⚠️ Android

If your device version is on Android 10 or below, you can directly find the log file in Android/data//files/ If your device version is on Android 11 and if you have The Permissions Utils component on your app, you can get a log file of the previous month and the current one with the method getZippedLogUriFiles(), or by clicking on “Contact support” and change the email receiver. The file will be in attachment of the email.

ℹ️ iOS

Log will be written in app directory. One log file per month will be written with the name log-\<YEAR>-\<MONTH>.txt (example: log-2019-8.txt). All DriveKit modules log in this file.

You can make files of your application (including DriveKit log files) available in the iOS Files app by adding these 2 keys to your project's Info.plist file: UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace, setting them both to true.

⚠️ iOS

To write log files on user smartphone, you must add the following entry in your info.plist file UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace set to true.

Disable logging by calling:

disableLogging();

To enable logging, call the following method specifying the path of the log directory.

enableLogging({ logPath: '/path/to/my/log/directory' });

isTokenValid

  isTokenValid(): Promise<boolean>

Once you are connected to the SDK with your key and a user ID, you can check the validity of the generated token by calling:

const isValid = await isTokenValid();

getUserInfo

getUserInfo(
  synchronizationType: 'default' | 'cache' = 'default'
): Promise<UserInfo | null>
UserInfoType
firstnamestring \| null
lastnamestring \| null
pseudostring \| null

To get user’s information (first name, last name and pseudo), call the getUserInfo method. It will retrieve and save these data locally:

const userInfo = await getUserInfo();

updateUserInfo

updateUserInfo(
  userInfo: UserInfo
): Promise<void>
UserInfoType
firstnamestring \| null
lastnamestring \| null
pseudostring \| null

You can add information to a user's account such as first name, last name and pseudo. These details are optional and you can choose to make the user's account anonymous. To update the user's information, you must call the updateUserInfo method:

await updateUserInfo({
  firstname: 'firstname',
  lastname: 'lastname',
  pseudo: 'pseudo',
});

getUriLogFile

  getUriLogFile(): Promise<{ uri: string } | null>;

You can retrieve the Uri log file by calling the following method:

const { uri } = await getUriLogFile();

composeDiagnosisMail

  composeDiagnosisMail(): Promise<void>

You can compose a diagnosis mail with attached DriveKit logs (if available). To do this, call this following method:

DriveKit.composeDiagnosisMail({
  recipients: [],
  bccRecipients: [],
  subject: 'Diagnosis mail',
  body: '',
});

requestIOSLocationPermission

  requestIOSLocationPermission(): Promise<void>

It's recommended to use this method to ask for the location permission for iOS

await requestIOSLocationPermission();
2.0.2

5 days ago

2.0.1

23 days ago

2.0.0

24 days ago

1.9.0

3 months ago

1.8.1

3 months ago

1.8.0

4 months ago

1.7.0

5 months ago

1.6.0

7 months ago

1.5.2

12 months ago

1.5.1

12 months ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.1-alpha.0

2 years ago