Skip to main content

Usage: User initialization

Configure a user for data synchronization.

Update userID

Update the userID:

void updateUserID() {
AHRookConfigurationManager.updateUserID(userID).then((_) {
// Success
}).catchError((exception) {
// Handle error
});
}
info

Any call to updateUserID with a different userID will override the previous userID and reset the sync status, so if you are using Background sync or Continuous upload all health data will synchronize again in background or the next time the app is opened.

Login / Logout

The updateUserID function should be called as part of your login and initialization process. When your users logout from your app, you'll have two options:

  1. Call clearUserID to remove the userID from SDK.
  2. deleteUserFromRook to remove the userID from SDK and disable it in server (Only disable from Apple Health data source).

If you have previously called updateUserID and the app is restarted (closed and opened) you won't have to call updateUserID again.

After initializing you can call getUserID and verify that the userID was autoconfigured (recovered from preferences).

void checkUserIDRegistered() {
AHRookConfigurationManager.getUserID().then((userID) {
if (userID != null) {
// userID was autoconfigured (recovered from preferences), no need to call AHRookConfigurationManager.updateUserID()
} else {
// userID wasn't autoconfigured (recovered from preferences), MUST call AHRookConfigurationManager.updateUserID()
}
});
}

User timezone

Every time updateUserID completes successfully the timezone information will be updated.

In most cases the above behavior is more than enough. If you need to update the timezone information manually call syncUserTimeZone:

void updateTimeZoneInformation() {
AHRookConfigurationManager.syncUserTimeZone().then((_) {
// Success
}).catchError((exception) {
// Handle error
});
}