AWSIoTManager Class Reference

Inherits from AWSService : NSObject
Declared in AWSIoTManager.h
AWSIoTManager.m

  configuration

The service configuration used to instantiate this service client.

@property (nonatomic, strong, readonly) AWSServiceConfiguration *configuration

Discussion

Warning: Once the client is instantiated, do not modify the configuration object. It may cause unspecified behaviors.

Declared In

AWSIoTManager.h

+ defaultIoTManager

Returns the singleton service client. If the singleton object does not exist, the SDK instantiates the default service client with defaultServiceConfiguration from [AWSServiceManager defaultServiceManager]. The reference to this object is maintained by the SDK, and you do not need to retain it manually.

+ (instancetype)defaultIoTManager

Return Value

The default service client.

Discussion

For example, set the default service configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
     let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
     let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
     AWSServiceManager.default().defaultServiceConfiguration = configuration

     return true
 }

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                      identityPoolId:@"YourIdentityPoolId"];
      AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
                                                                           credentialsProvider:credentialsProvider];
      [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

      return YES;
  }

Then call the following to get the default service client:

Swift

 let IoTManager = AWSIoTManager.default()

Objective-C

 AWSIoTManager *IoTManager = [AWSIoTManager defaultIoTManager];

Declared In

AWSIoTManager.h

+ registerIoTManagerWithConfiguration:forKey:

Creates a service client with the given service configuration and registers it for the key.

+ (void)registerIoTManagerWithConfiguration:(AWSServiceConfiguration *)configuration forKey:(NSString *)key

Parameters

configuration

A service configuration object.

key

A string to identify the service client.

Discussion

For example, set the default service configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
     let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
     let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
     AWSIoTManager.register(with: configuration!, forKey: "USWest2IoTManager")

     return true
 }

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                     identityPoolId:@"YourIdentityPoolId"];
     AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
                                                                          credentialsProvider:credentialsProvider];

     [AWSIoTManager registerIoTManagerWithConfiguration:configuration forKey:@"USWest2IoTManager"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let IoTManager = AWSIoTManager(forKey: "USWest2IoTManager")

Objective-C

 AWSIoTManager *IoTManager = [AWSIoTManager IoTManagerForKey:@"USWest2IoTManager"];

Warning: After calling this method, do not modify the configuration object. It may cause unspecified behaviors.

Declared In

AWSIoTManager.h

+ IoTManagerForKey:

Retrieves the service client associated with the key. You need to call + registerIoTManagerWithConfiguration:forKey: before invoking this method.

+ (instancetype)IoTManagerForKey:(NSString *)key

Parameters

key

A string to identify the service client.

Return Value

An instance of the service client.

Discussion

For example, set the default service configuration in - application:didFinishLaunchingWithOptions:

Swift

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
     let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
     let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
     AWSIoTManager.register(with: configuration!, forKey: "USWest2IoTManager")

     return true
 }

Objective-C

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                     identityPoolId:@"YourIdentityPoolId"];
     AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
                                                                          credentialsProvider:credentialsProvider];

     [AWSIoTManager registerIoTManagerWithConfiguration:configuration forKey:@"USWest2IoTManager"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let IoTManager = AWSIoTManager(forKey: "USWest2IoTManager")

Objective-C

 AWSIoTManager *IoTManager = [AWSIoTManager IoTManagerForKey:@"USWest2IoTManager"];

Declared In

AWSIoTManager.h

+ removeIoTManagerForKey:

Removes the service client associated with the key and release it.

+ (void)removeIoTManagerForKey:(NSString *)key

Parameters

key

A string to identify the service client.

Discussion

Warning: Before calling this method, make sure no method is running on this client.

Declared In

AWSIoTManager.h

– createKeysAndCertificateFromCsr:callback:

Creates keys and certificate from a CSR created using the specified dictionary

- (void)createKeysAndCertificateFromCsr:(NSDictionary<NSString*,NSString*> *)csrDictionary callback:(void ( ^ ) ( AWSIoTCreateCertificateResponse *mainResponse ))callback

Parameters

csrDictionary

contains values used to generate the CSR. Requires values for keys: commonName, countryName, organizationName, organizationalUnitName

callback

When new certificate is created the function of block will be called with an instance of AWSIOTDescribeCertificateResponse

Declared In

AWSIoTManager.h

+ importIdentityFromPKCS12Data:passPhrase:certificateId:

Import PKCS12 identity into keychain. This method allows you to import an identity created using the AWS console or CLI into the keychain. The identity is contained in PKCS12 data; you can create PKCS12 files (suffix .p12) using openssl as follows:

+ (BOOL)importIdentityFromPKCS12Data:(NSData *)pkcs12Data passPhrase:(NSString *)passPhrase certificateId:(NSString *)certificateId

Parameters

pkcs12Data

pkcs12 raw data. Will only import the first item.

passPhrase

Pass phrase used to decrypt the pkcs12 data.

certificateId

Unique identifier used to find the key/certificate for use.

Discussion

openssl pkcs12 -export -in cert.pem -inkey key.pem -CAfile root-ca.crt -out awsiot-identity.p12

Declared In

AWSIoTManager.h

+ isValidCertificate:

Validates the certificate with the given identifier of certificate.

+ (BOOL)isValidCertificate:(NSString *)certificateId

Parameters

certificateId

The certificate identifier

Return Value

TRUE if certificate is valid, else FALSE

Declared In

AWSIoTManager.h

+ deleteCertificate

Deletes keys and certificate

+ (BOOL)deleteCertificate

Return Value

TRUE if certificate is deleted, else FALSE

Declared In

AWSIoTManager.h