AWSIoTData Class Reference

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

Overview

AWS IoT

AWS IoT-Data enables secure, bi-directional communication between Internet-connected things (such as sensors, actuators, embedded devices, or smart appliances) and the AWS cloud. It implements a broker for applications and things to publish messages over HTTP (Publish) and retrieve, update, and delete thing shadows. A thing shadow is a persistent representation of your things and their state in the AWS cloud.

  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

AWSIoTDataService.h

+ defaultIoTData

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

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 IoTData = AWSIoTData.default()

Objective-C

 AWSIoTData *IoTData = [AWSIoTData defaultIoTData];

Declared In

AWSIoTDataService.h

+ registerIoTDataWithConfiguration:forKey:

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

+ (void)registerIoTDataWithConfiguration:(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)
    AWSIoTData.register(with: configuration!, forKey: "USWest2IoTData")

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

     [AWSIoTData registerIoTDataWithConfiguration:configuration forKey:@"USWest2IoTData"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let IoTData = AWSIoTData(forKey: "USWest2IoTData")

Objective-C

 AWSIoTData *IoTData = [AWSIoTData IoTDataForKey:@"USWest2IoTData"];

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

Declared In

AWSIoTDataService.h

+ IoTDataForKey:

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

+ (instancetype)IoTDataForKey:(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)
    AWSIoTData.register(with: configuration!, forKey: "USWest2IoTData")

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

     [AWSIoTData registerIoTDataWithConfiguration:configuration forKey:@"USWest2IoTData"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let IoTData = AWSIoTData(forKey: "USWest2IoTData")

Objective-C

 AWSIoTData *IoTData = [AWSIoTData IoTDataForKey:@"USWest2IoTData"];

Declared In

AWSIoTDataService.h

+ removeIoTDataForKey:

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

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

AWSIoTDataService.h

– deleteThingShadow:

Deletes the thing shadow for the specified thing.

For more information, see DeleteThingShadow in the AWS IoT Developer Guide.

- (AWSTask<AWSIoTDataDeleteThingShadowResponse*> *)deleteThingShadow:(AWSIoTDataDeleteThingShadowRequest *)request

Parameters

request

A container for the necessary parameters to execute the DeleteThingShadow service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSIoTDataDeleteThingShadowResponse. On failed execution, task.error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorResourceNotFound, AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorThrottling, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorServiceUnavailable, AWSIoTDataErrorInternalFailure, AWSIoTDataErrorMethodNotAllowed, AWSIoTDataErrorUnsupportedDocumentEncoding.

Declared In

AWSIoTDataService.h

– deleteThingShadow:completionHandler:

Deletes the thing shadow for the specified thing.

For more information, see DeleteThingShadow in the AWS IoT Developer Guide.

- (void)deleteThingShadow:(AWSIoTDataDeleteThingShadowRequest *)request completionHandler:(void ( ^ _Nullable ) ( AWSIoTDataDeleteThingShadowResponse *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the DeleteThingShadow service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorResourceNotFound, AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorThrottling, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorServiceUnavailable, AWSIoTDataErrorInternalFailure, AWSIoTDataErrorMethodNotAllowed, AWSIoTDataErrorUnsupportedDocumentEncoding.

Declared In

AWSIoTDataService.h

– getThingShadow:

Gets the thing shadow for the specified thing.

For more information, see GetThingShadow in the AWS IoT Developer Guide.

- (AWSTask<AWSIoTDataGetThingShadowResponse*> *)getThingShadow:(AWSIoTDataGetThingShadowRequest *)request

Parameters

request

A container for the necessary parameters to execute the GetThingShadow service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSIoTDataGetThingShadowResponse. On failed execution, task.error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorResourceNotFound, AWSIoTDataErrorThrottling, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorServiceUnavailable, AWSIoTDataErrorInternalFailure, AWSIoTDataErrorMethodNotAllowed, AWSIoTDataErrorUnsupportedDocumentEncoding.

Declared In

AWSIoTDataService.h

– getThingShadow:completionHandler:

Gets the thing shadow for the specified thing.

For more information, see GetThingShadow in the AWS IoT Developer Guide.

- (void)getThingShadow:(AWSIoTDataGetThingShadowRequest *)request completionHandler:(void ( ^ _Nullable ) ( AWSIoTDataGetThingShadowResponse *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the GetThingShadow service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorResourceNotFound, AWSIoTDataErrorThrottling, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorServiceUnavailable, AWSIoTDataErrorInternalFailure, AWSIoTDataErrorMethodNotAllowed, AWSIoTDataErrorUnsupportedDocumentEncoding.

Declared In

AWSIoTDataService.h

– publish:

Publishes state information.

For more information, see HTTP Protocol in the AWS IoT Developer Guide.

- (AWSTask *)publish:(AWSIoTDataPublishRequest *)request

Parameters

request

A container for the necessary parameters to execute the Publish service method.

Return Value

An instance of AWSTask. On successful execution, task.result will be nil. On failed execution, task.error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorInternalFailure, AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorMethodNotAllowed.

Declared In

AWSIoTDataService.h

– publish:completionHandler:

Publishes state information.

For more information, see HTTP Protocol in the AWS IoT Developer Guide.

- (void)publish:(AWSIoTDataPublishRequest *)request completionHandler:(void ( ^ _Nullable ) ( NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the Publish service method.

completionHandler

The completion handler to call when the load request is complete. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorInternalFailure, AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorMethodNotAllowed.

Declared In

AWSIoTDataService.h

– updateThingShadow:

Updates the thing shadow for the specified thing.

For more information, see UpdateThingShadow in the AWS IoT Developer Guide.

- (AWSTask<AWSIoTDataUpdateThingShadowResponse*> *)updateThingShadow:(AWSIoTDataUpdateThingShadowRequest *)request

Parameters

request

A container for the necessary parameters to execute the UpdateThingShadow service method.

Return Value

An instance of AWSTask. On successful execution, task.result will contain an instance of AWSIoTDataUpdateThingShadowResponse. On failed execution, task.error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorConflict, AWSIoTDataErrorRequestEntityTooLarge, AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorThrottling, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorServiceUnavailable, AWSIoTDataErrorInternalFailure, AWSIoTDataErrorMethodNotAllowed, AWSIoTDataErrorUnsupportedDocumentEncoding.

Declared In

AWSIoTDataService.h

– updateThingShadow:completionHandler:

Updates the thing shadow for the specified thing.

For more information, see UpdateThingShadow in the AWS IoT Developer Guide.

- (void)updateThingShadow:(AWSIoTDataUpdateThingShadowRequest *)request completionHandler:(void ( ^ _Nullable ) ( AWSIoTDataUpdateThingShadowResponse *_Nullable response , NSError *_Nullable error ))completionHandler

Parameters

request

A container for the necessary parameters to execute the UpdateThingShadow service method.

completionHandler

The completion handler to call when the load request is complete. response - A response object, or nil if the request failed. error - An error object that indicates why the request failed, or nil if the request was successful. On failed execution, error may contain an NSError with AWSIoTDataErrorDomain domain and the following error code: AWSIoTDataErrorConflict, AWSIoTDataErrorRequestEntityTooLarge, AWSIoTDataErrorInvalidRequest, AWSIoTDataErrorThrottling, AWSIoTDataErrorUnauthorized, AWSIoTDataErrorServiceUnavailable, AWSIoTDataErrorInternalFailure, AWSIoTDataErrorMethodNotAllowed, AWSIoTDataErrorUnsupportedDocumentEncoding.

Declared In

AWSIoTDataService.h