react-native-here-mobility-sdk
Version:
Offical Here Mobility SDK for react native to access Here's marketplace features
52 lines (45 loc) • 1.45 kB
JavaScript
/**********************************************************
* Copyright © 2018 HERE Global B.V. All rights reserved. *
**********************************************************/
import { NativeModules } from "react-native";
import { User } from "./models/User";
/**
* HereMobilitySDK is the client wrapper for accessing the HereSDKManager API.
*/
class HereMobilitySDK {
/**
* Sets the current user of the SDK (creates a HereSDKUser instance). To unregister the user, call setUser with a null parameter.
*
* @param {User} user The unique ID of the user.
*/
static setUser(user: ?User) {
NativeModules.HereMobilitySDK.setUser(user);
}
/**
* Gets the HereSDKUser instance of the user currently logged in.
*
* @param callback A callback function which will be called with the current user, or nil if no user is registered.
*/
static getUser(callback: (user: ?User) => void) {
NativeModules.HereMobilitySDK.getUser(function(user) {
if (user) {
callback(JSON.parse(user));
} else {
callback(null);
}
});
}
/**
* Gets the HereSDKUser logging id.
*
* @return A promise that resolve the logging id.
*/
static getLoggingId(): Promise {
return new Promise(function(resolve, reject) {
NativeModules.HereMobilitySDK.getLoggingId(function(loggingId) {
resolve(loggingId);
});
});
}
}
module.exports = HereMobilitySDK;