Skip to main content

Usage: SDK initialization

Set your credentials and get authorization of usage.

Initialize

To initialize call initRook with your credentials and an environment:.

void initialize() {
const environment =
kDebugMode ? RookEnvironment.sandbox : RookEnvironment.production;

final rookConfiguration = RookConfiguration(
clientUUID: clientUUID,
secret: secret,
environment: environment,
// If true steps tracking, background sync (on supported devices)
// and yesterday sync (when background sync is not supported) will start when the SDK is initialized
enableBackgroundSync: true,
);

// MUST be called first if you want to enable native logs
if (kDebugMode) {
HCRookConfigurationManager.enableNativeLogs();
}

HCRookConfigurationManager.setConfiguration(rookConfiguration);

HCRookConfigurationManager.initRook().then((_) {
// Success
}).catchError((exception) {
// Hanlde error
});
}
tip

We recommend you to ask your users if they want to enable the automatic sync and steps tracking, then save their preference in local storage and set enableBackgroundSync conditionally.

Critical Requirement

You must register your applicationId (package name) and its corresponding secret in the ROOK Portal before attempting to initialize the SDK. Failure to register these credentials will cause the initialization to fail with an SDKNotAuthorizedException.

The ROOK Portal supports independent configurations for Sandbox and Production environments. Each environment requires its own unique pair of Package Name and secret.

If you come from a previous version you MUST re-initialize the SDK with the new authentication flow.

Recommendations

When you initialize with initRook the SDK an HTTP request is made, so you should only initialize the sdk once.