AWSIoTDataManager Class Reference

Inherits from AWSService : NSObject
Declared in AWSIoTDataManager.h
AWSIoTDataManager.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

AWSIoTDataManager.h

  mqttConfiguration

The MQTT configuration used by this service client. Any changes to this configuration object will take effect upon the next invocation of either the connectWithClientId or connectUsingWebSocketWithClientId methods.

@property (nonatomic, strong) AWSIoTMQTTConfiguration *mqttConfiguration

Declared In

AWSIoTDataManager.h

+ defaultIoTDataManager

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)defaultIoTDataManager

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 IoTDataManager = AWSIoTDataManager.default()

Objective-C

 AWSIoTDataManager *IoTDataManager = [AWSIoTDataManager defaultIoTDataManager];

Declared In

AWSIoTDataManager.h

+ registerIoTDataManagerWithConfiguration:forKey:

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

+ (void)registerIoTDataManagerWithConfiguration:(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)
     AWSIoTDataManager.register(with: configuration!, forKey: "USWest2IoTDataManager")

     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];

     [AWSIoTDataManager registerIoTDataManagerWithConfiguration:configuration forKey:@"USWest2IoTDataManager"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let IoTDataManager = AWSIoTDataManager(forKey: "USWest2IoTDataManager")

Objective-C

 AWSIoTDataManager *IoTDataManager = [AWSIoTDataManager IoTDataManagerForKey:@"USWest2IoTDataManager"];

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

Declared In

AWSIoTDataManager.h

+ IoTDataManagerForKey:

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

+ (instancetype)IoTDataManagerForKey:(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)
     AWSIoTDataManager.register(with: configuration!, forKey: "USWest2IoTDataManager")

     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];

     [AWSIoTDataManager registerIoTDataManagerWithConfiguration:configuration forKey:@"USWest2IoTDataManager"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let IoTDataManager = AWSIoTDataManager(forKey: "USWest2IoTDataManager")

Objective-C

 AWSIoTDataManager *IoTDataManager = [AWSIoTDataManager IoTDataManagerForKey:@"USWest2IoTDataManager"];

Declared In

AWSIoTDataManager.h

+ removeIoTDataManagerForKey:

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

+ (void)removeIoTDataManagerForKey:(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

AWSIoTDataManager.h

– connectWithClientId:cleanSession:certificateId:statusCallback:

Initialises the MQTT session and connects to AWS IoT using certificate-based mutual authentication

- (BOOL)connectWithClientId:(NSString *)clientId cleanSession:(BOOL)cleanSession certificateId:(NSString *)certificateId statusCallback:(void ( ^ ) ( AWSIoTMQTTStatus status ))callback

Parameters

clientId

The Client Identifier identifies the Client to the Server.

cleanSession

specifies if the server should discard previous session information.

certificateId

contains the ID of the certificate to use in the connection; must be in the keychain

block

Reference. When new mqtt session status is received the function of block will be called with new connection status.

Return Value

true if initialise finished with success

Declared In

AWSIoTDataManager.h

– connectUsingWebSocketWithClientId:cleanSession:statusCallback:

Initialises the MQTT session and connects to AWS IoT using WebSocket/SigV4 authentication. IAM credentials are taken from the current service configuration.

- (BOOL)connectUsingWebSocketWithClientId:(NSString *)clientId cleanSession:(BOOL)cleanSession statusCallback:(void ( ^ ) ( AWSIoTMQTTStatus status ))callback

Parameters

clientId

The Client Identifier identifies the Client to the Server.

cleanSession

specifies if the server should discard previous session information.

block

Reference. When new mqtt session status is received the function of block will be called with new connection status.

Return Value

true if initialise finished with success

Declared In

AWSIoTDataManager.h

– disconnect

Disconnect from a mqtt client (close current mqtt session)

- (void)disconnect

Declared In

AWSIoTDataManager.h

– publishString:onTopic:QoS:

Send MQTT message to specified topic

- (BOOL)publishString:(NSString *)string onTopic:(NSString *)topic QoS:(AWSIoTMQTTQoS)qos

Parameters

topic

The topic for publish to.

qos

The QoS value to use when publishing (optional, default AWSIoTMQTTQoSAtMostOnce).

message

The message (As NSString object) to be sent.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– publishData:onTopic:QoS:

Send MQTT message to specified topic

- (BOOL)publishData:(NSData *)data onTopic:(NSString *)topic QoS:(AWSIoTMQTTQoS)qos

Parameters

topic

The topic for publish to.

qos

The QoS value to use when publishing (optional, default AWSIoTMQTTQoSAtMostOnce).

message

The message (As NSData) to be sent.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– subscribeToTopic:QoS:messageCallback:

Subscribes to a topic at a specific QoS level

- (BOOL)subscribeToTopic:(NSString *)topic QoS:(AWSIoTMQTTQoS)qos messageCallback:(AWSIoTMQTTNewMessageBlock)callback

Parameters

topic

The Topic to subscribe to.

qos

Specifies the QoS Level of the subscription: AWSIoTMQTTQoSAtMostOnce or AWSIoTMQTTQoSAtLeastOnce

block

Reference to AWSIOTMQTTNewMessageBlock. When new message is received the block will be invoked.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– subscribeToTopic:QoS:extendedCallback:

Subscribes to a topic at a specific QoS level

- (BOOL)subscribeToTopic:(NSString *)topic QoS:(AWSIoTMQTTQoS)qos extendedCallback:(AWSIoTMQTTExtendedNewMessageBlock)callback

Parameters

topic

The Topic to subscribe to.

qos

Specifies the QoS Level of the subscription: AWSIoTMQTTQoSAtMostOnce or AWSIoTMQTTQoSAtLeastOnce

block

Reference to AWSIOTMQTTExtendedNewMessageBlock. When new message is received the block will be invoked.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– unsubscribeTopic:

Unsubscribes from a topic

- (void)unsubscribeTopic:(NSString *)topic

Parameters

topic

The Topic to unsubscribe from.

Declared In

AWSIoTDataManager.h

– registerWithShadow:options:eventCallback:

Register for updates on a device shadow

- (BOOL)registerWithShadow:(NSString *)name options:(NSDictionary<NSString*,NSNumber*> *_Nullable)options eventCallback:(void ( ^ ) ( NSString *name , AWSIoTShadowOperationType operation , AWSIoTShadowOperationStatusType status , NSString *clientToken , NSData *payload ))callback

Parameters

name

The device shadow to register for updates on.

options

A dictionary with device shadow registration options. The options are:

enableDebugging: BOOL, set to YES to enable additional console debugging (default NO) enableVersioning: BOOL, set to NO to disable versioning (default YES) enableForeignStateUpdateNotifications: BOOL, set to YES to enable foreign state updates (default NO) enableStaleDiscards: BOOL, set to NO to disable discarding stale updates (default YES) enableIgnoreDeltas: BOOL, set to YES to disable delta updates (default NO) QoS: AWSIoTMQTTQoS (default AWSIoTMQTTQoSMessageDeliveryAttemptedAtMostOnce) shadowOperationTimeoutSeconds: double, device shadow operation timeout (default 10.0)

eventCallback

The function to call when updates are received for the device shadow.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– unregisterFromShadow:

Unregister from updates on a device shadow

- (BOOL)unregisterFromShadow:(NSString *)name

Parameters

name

The device shadow to unregister from updates on.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– updateShadow:jsonString:

Update a device shadow

- (BOOL)updateShadow:(NSString *)name jsonString:(NSString *)jsonString

Parameters

name

The device shadow to update.

jsonString

The JSON string to update the device shadow with.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– updateShadow:jsonString:clientToken:

Update a device shadow

- (BOOL)updateShadow:(NSString *)name jsonString:(NSString *)jsonString clientToken:(NSString *_Nullable)clientToken

Parameters

name

The device shadow to update.

jsonString

The JSON string to update the device shadow with.

clientToken

A client token value to use when updating the device shadow.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– getShadow:

Get a device shadow

- (BOOL)getShadow:(NSString *)name

Parameters

name

The device shadow to get.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– getShadow:clientToken:

Get a device shadow

- (BOOL)getShadow:(NSString *)name clientToken:(NSString *_Nullable)clientToken

Parameters

name

The device shadow to get.

clientToken

A client token to use when requesting the device shadow.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– deleteShadow:

Delete a device shadow

- (BOOL)deleteShadow:(NSString *)name

Parameters

name

The device shadow to delete.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h

– deleteShadow:clientToken:

Delete a device shadow

- (BOOL)deleteShadow:(NSString *)name clientToken:(NSString *_Nullable)clientToken

Parameters

name

The device shadow to delete.

clientToken

A client token to use when deleting the device shadow.

Return Value

Boolean value indicating success or failure.

Declared In

AWSIoTDataManager.h