AWSCognito Class Reference

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

  configuration

The error domain for AWSCognito errors.

  • AWSCognitoErrorUnknown - Unknow error.
  • AWSCognitoErrorRemoteDataStorageFailed - The Amazon Cognito call temporarily failed.
  • AWSCognitoErrorInvalidDataValue - The Amazon Cognito call failed. The value for the key is invalid and has been deleted from the local database.
  • AWSCognitoErrorDataSizeLimitExceeded - The Amazon Cognito call failed. A dataset has exceeded the max dataset size.
  • AWSCognitoErrorLocalDataStorageFailed - The SQLite call failed.
  • AWSCognitoErrorIllegalArgument - The input value is invalid.
  • AWSCognitoErrorConflictRetriesExhausted - The number of attempts to resolve a conflict has exceeded the max number of retries.
  • AWSCognitoErrorWiFiNotAvailable - WiFi is required and not currently available.
  • AWSCognitoErrorDeviceNotRegistered - The device has not been registered yet.
  • AWSCognitoErrorSyncAlreadyPending - This sync is unecessary, there is already a pending sync.
  • AWSCognitoErrorTimedOutWaitingForInFlightSync - There is a in flight sync that took over 5 minutes to complete, so this one was cancelled.
@property (nonatomic, strong, readonly) AWSServiceConfiguration *configuration

Declared In

AWSCognitoService.h

  conflictHandler

A conflict resolution handler that will receive calls when there is a conflict during a sync operation. A conflict will occur when both remote and local data have been updated since the last sync time. When not explicitly set, we will use the default conflict resolution of ‘last writer wins’, where the data most recently updated will be persisted. This handler will be propagated to any AWSCognitoDataset opened by this client.

@property (nonatomic, strong) AWSCognitoRecordConflictHandler conflictHandler

Declared In

AWSCognitoService.h

  datasetDeletedHandler

A deleted dataset handler. This handler will be called during a synchronization when the remote service indicates that a dataset has been deleted. Returning YES from the handler will cause the service to recreate the dataset on the remote on the next synchronization. Returning NO or leaving this property nil will cause the client to delete the dataset locally. This handler will be propagated to any AWSCognitoDataset opened by this client.

@property (nonatomic, strong) AWSCognitoDatasetDeletedHandler datasetDeletedHandler

Declared In

AWSCognitoService.h

  datasetMergedHandler

A merged dataset handler. This handler will be called during a synchronization when the remote service indicates that other datasets should be merged with this one. Merged datasets should be fetched, their data overlayed locally and then removed. Failing to implement this handler will result in merged datasets remaining on the service indefinitely. This handler will be propagated to any AWSCognitoDataset opened by this client.

@property (nonatomic, strong) AWSCognitoDatasetMergedHandler datasetMergedHandler

Declared In

AWSCognitoService.h

  deviceId

The identifier used for this client in Amazon Cognito. If not supplied Amazon Cognito will create a random GUID for the device.

@property (nonatomic, strong) NSString *deviceId

Declared In

AWSCognitoService.h

  synchronizeRetries

The number of times to attempt a synchronization before failing. This will be set on any AWSCognitoDatasets opened with this client. Defaults to 5 if not set.

@property (nonatomic, assign) uint32_t synchronizeRetries

Declared In

AWSCognitoService.h

  synchronizeOnWiFiOnly

Only synchronize if device is on a WiFi network. Defaults to NO if not set.

@property (nonatomic, assign) BOOL synchronizeOnWiFiOnly

Declared In

AWSCognitoService.h

+ defaultCognito

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. Returns nil if the credentials provider is not an instance of AWSCognitoCredentials provider.

+ (instancetype)defaultCognito

Return Value

The default service client.

Discussion

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

Swift

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> 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 Cognito = AWSCognito.default()

Objective-C

 AWSCognito *Cognito = [AWSCognito defaultCognito];

Declared In

AWSCognitoService.h

+ registerCognitoWithConfiguration:forKey:

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

+ (void)registerCognitoWithConfiguration:(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: [NSObject: AnyObject]?) -> Bool {
     let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
     let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
     AWSCognito.register(with: configuration!, forKey: "USWest2Cognito")

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

     [AWSCognito registerCognitoWithConfiguration:configuration forKey:@"USWest2Cognito"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let Cognito = AWSCognito(forKey: "USWest2Cognito")

Objective-C

 AWSCognito *Cognito = [AWSCognito CognitoForKey:@"USWest2Cognito"];

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

Declared In

AWSCognitoService.h

+ CognitoForKey:

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

+ (instancetype)CognitoForKey:(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: [NSObject: AnyObject]?) -> Bool {
     let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
     let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
     AWSCognito.register(with: configuration!, forKey: "USWest2Cognito")

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

     [AWSCognito registerCognitoWithConfiguration:configuration forKey:@"USWest2Cognito"];

     return YES;
 }

Then call the following to get the service client:

Swift

 let Cognito = AWSCognito(forKey: "USWest2Cognito")

Objective-C

 AWSCognito *Cognito = [AWSCognito CognitoForKey:@"USWest2Cognito"];

Declared In

AWSCognitoService.h

+ removeCognitoForKey:

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

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

AWSCognitoService.h

– openOrCreateDataset:

Opens an existing dataset or creates a new one.

- (AWSCognitoDataset *)openOrCreateDataset:(NSString *)datasetName

Return Value

handle to AWSCognitoDataset

Declared In

AWSCognitoService.h

– listDatasets

List all datasets our client is aware of. Call refreshDatasetMetadata to ensure the client has knowledge of all datasets available on the remote store.

- (NSArray<AWSCognitoDatasetMetadata*> *)listDatasets

Return Value

NSArray of AWSCognitoDatasetMetadata

Declared In

AWSCognitoService.h

– refreshDatasetMetadata

List all of the datasets. Returns a AWSTask. The result of this task will be an array of AWSCognitoDatasetMetadata objects.

- (AWSTask<NSArray<AWSCognitoDatasetMetadata*> *> *)refreshDatasetMetadata

Declared In

AWSCognitoService.h

– wipe

Wipe all cached data.

- (void)wipe

Declared In

AWSCognitoService.h

+ defaultConflictHandler

Get the default, last writer wins conflict handler

+ (AWSCognitoRecordConflictHandler)defaultConflictHandler

Declared In

AWSCognitoService.h

– registerDevice:

Register this device for push notifications. You will not receive any notifications until you actually subscribe the dataset you want to receive push notifications for. If your build targets Release, this will register the device with APNS, if your build targets Debug this will register the device with APNS_SANDBOX. Returns a AWSTask. The result of this task will be a AWSCognitoSyncRegisterDeviceResponse.

- (AWSTask *)registerDevice:(NSData *)deviceToken

Declared In

AWSCognitoService.h

+ cognitoDeviceId

Get the device id Cognito Sync gave this device. nil if device has never been registered

+ (NSString *)cognitoDeviceId

Declared In

AWSCognitoService.h

+ setPushPlatform:

Used to override the platform for push notifications. If you are not using the CocoaPods distribution,

ifdef DEBUG

[[AWSCognito defaultCognito] setPushPlatform:AWSCognitoSyncPlatformApnsSandbox];

endif

will set push notifications to use the APNS_SANDBOX if your build targets Debug. Otherwise it will always use APNS.

+ (void)setPushPlatform:(AWSCognitoSyncPlatform)pushPlatform

Declared In

AWSCognitoService.h

+ pushPlatform

The push platform for push notifications

+ (AWSCognitoSyncPlatform)pushPlatform

Declared In

AWSCognitoService.h

– subscribe:

Subscribe to a list of datasets. Make sure you have called synchronize on each of the datasets in the list at least once prior to calling this. Returns a AWSTask. The result of this task will be a NSArray of AWSCognitoSyncSubscribeToDatasetResponse

- (AWSTask *)subscribe:(NSArray<NSString*> *)datasetNames

Declared In

AWSCognitoService.h

– subscribeAll

Subscribe to all datasets you have locally. Make sure you have called synchronize on all of your local datasets at least once prior to calling this. Returns a AWSTask. The result of this task will be a NSArray of AWSCognitoSyncSubscribeToDatasetResponse

- (AWSTask *)subscribeAll

Declared In

AWSCognitoService.h

– unsubscribe:

Unsubscribe to a list of datasets. Returns a AWSTask. The result of this task will be a NSArray of AWSCognitoSyncUnsubscribeToDatasetResponse

- (AWSTask *)unsubscribe:(NSArray<NSString*> *)datasetNames

Declared In

AWSCognitoService.h

– unsubscribeAll

Unsubscribe to all datasets you have locally. Make sure you have called synchronize on all of your local datasets at least once prior to calling this. Returns a AWSTask. The result of this task will be a NSArray of AWSCognitoSyncUnsubscribeToDatasetResponse

- (AWSTask *)unsubscribeAll

Declared In

AWSCognitoService.h