...
Create an instance of
NMApiCredentials
with mandatory parameters (account ID, password, email ID, service ID) with one of the methods provided.Call the
+ (void)obtainApiKeyWithCredentials:completion:
method, to request a new API Key. A result is expected to come in the completion block.Check received API Key and
NSError
object. Non-empty error instance indicates a failed request. A type of received error. It’s error code corresponds an error type, specified inNMApiKeyObtainError
.
Example:
Code Block | ||
---|---|---|
| ||
NMApiCredentials *credentials = [NMApiCredentials alloc] initWithAccountId:@"yourAccountId" emailId:@"yourEmail" password:@"yourPAssword" serviceId:@(1234); [NMSdk obtainApiKeyWithCredentials:credentials completion:^(NSString * _Nullable apiKey, NSError * _Nullable error) { // if (error) { // Handle error // } // if (apiKey && [apiKey lenght] > 0) { // Store the received API key securely // Now you can start the SDK // [navmiiSDK startWithSettings:configurationSettings completion:nil]; // } // Next time pass the key to the SDK via NMConfigurationSettings object // NMConfigurationSettings *configurationSettings = [NMConfigurationSettings new]; // configurationSettings.apiKey = apiKey; // [navmiiSDK startWithSettings:configurationSettings setApiKeycompletion:apiKeynil]; }]; }); |
2. Storing the API Key Securely
...
When initializing the SDK, pass the stored API key to the NMConfigurationSettings
. To update the key after the SDK has been initialized, use the - (void)setApiKeyupdateApiKey:
method:
Code Block | ||
---|---|---|
| ||
NSString *storedApiKey = // Retrieve the stored API key [navmiiSDK setApiKeyupdateApiKey:storedApiKey]; |
4. Handling API Key Expiration
...
Code Block | ||
---|---|---|
| ||
BOOL isApiKeyExpired = [navmiiSDK isApiKeyExpired]; |
6. Error handling
+ (void)obtainApiKeyWithCredentials:completion:
method provides a convenient way to handle errors received on obtaining process. In the callback NSError
shares an error code. Possible values are:
NMApiKeyObtainErrorNoError - means no error received, API Key delivered successfully.
NMApiKeyObtainErrorUnknown - unknown error received.
NMApiKeyObtainErrorNetwork - networking error.
NMApiKeyObtainErrorBadResponse - no API Key obtained, check credentials submitted.