Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create an instance of NMApiCredentials with mandatory parameters (account ID, password, email ID, service ID) with one of the methods provided.

  2. Call the + (void)obtainApiKeyWithCredentials:completion: method, to request a new API Key. A result is expected to come in the completion block.

  3. 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 in NMApiKeyObtainError.

Example:

Code Block
languageobjective-c
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
languageobjective-c
NSString *storedApiKey = // Retrieve the stored API key
[navmiiSDK setApiKeyupdateApiKey:storedApiKey];

4. Handling API Key Expiration

...

Code Block
languageobjective-c
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.