AWSCognito
Deprecated
Use AWSAppSync
for data synchronization.
Objective-C
@interface AWSCognito
Swift
class AWSCognito
AWSCognito
Warning
The AWSCognito (Amazon Cognito Sync) SDK is deprecated. Please use AWSAppSync for data sync. @deprecated Please use AWSAppSync for data sync.-
Undocumented
Declaration
Objective-C
@property (nonatomic, strong, readonly) AWSServiceConfiguration *configuration
Swift
var configuration: UnsafeMutablePointer<Int32> { get }
-
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.
Declaration
Objective-C
@property (nonatomic, strong) AWSCognitoRecordConflictHandler _Nonnull conflictHandler;
Swift
var conflictHandler: AWSCognitoRecordConflictHandler { get set }
-
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.
Declaration
Objective-C
@property (nonatomic, strong) AWSCognitoDatasetDeletedHandler _Nonnull datasetDeletedHandler;
Swift
var datasetDeletedHandler: AWSCognitoDatasetDeletedHandler { get set }
-
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.
Declaration
Objective-C
@property (nonatomic, strong) AWSCognitoDatasetMergedHandler _Nonnull datasetMergedHandler;
Swift
var datasetMergedHandler: AWSCognitoDatasetMergedHandler { get set }
-
The identifier used for this client in Amazon Cognito. If not supplied Amazon Cognito will create a random GUID for the device.
Declaration
Objective-C
@property (nonatomic, strong) NSString *_Nonnull deviceId;
Swift
var deviceId: String { get set }
-
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.
Declaration
Objective-C
@property (nonatomic) uint32_t synchronizeRetries;
Swift
var synchronizeRetries: UInt32 { get set }
-
Only synchronize if device is on a WiFi network. Defaults to NO if not set.
Declaration
Objective-C
@property (nonatomic) BOOL synchronizeOnWiFiOnly;
Swift
var synchronizeOnWiFiOnly: Bool { get set }
-
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. Returnsnil
if the credentials provider is not an instance ofAWSCognitoCredentials
provider.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];
Declaration
Objective-C
+ (nonnull instancetype)defaultCognito;
Swift
class func `default`() -> Self
Return Value
The default service client.
-
Creates a service client with the given service configuration and registers it for the key.
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.
Declaration
Objective-C
+ (void)registerCognitoWithConfiguration:(id)configuration forKey:(nonnull NSString *)key;
Swift
class func register(withConfiguration configuration: Any!, forKey key: String)
Parameters
configuration
A service configuration object.
key
A string to identify the service client.
-
Retrieves the service client associated with the key. You need to call
+ registerCognitoWithConfiguration:forKey:
before invoking this method.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"];
Declaration
Objective-C
+ (nonnull instancetype)CognitoForKey:(nonnull NSString *)key;
Swift
convenience init(forKey key: String)
Parameters
key
A string to identify the service client.
Return Value
An instance of the service client.
-
Removes the service client associated with the key and release it.
Warning
Before calling this method, make sure no method is running on this client.
Declaration
Objective-C
+ (void)removeCognitoForKey:(nonnull NSString *)key;
Swift
class func remove(forKey key: String)
Parameters
key
A string to identify the service client.
-
Opens an existing dataset or creates a new one.
Declaration
Objective-C
- (nonnull AWSCognitoDataset *)openOrCreateDataset: (nonnull NSString *)datasetName;
Swift
func openOrCreateDataset(_ datasetName: String) -> AWSCognitoDataset
Return Value
handle to AWSCognitoDataset
-
List all datasets our client is aware of. Call refreshDatasetMetadata to ensure the client has knowledge of all datasets available on the remote store.
Declaration
Objective-C
- (nonnull NSArray<AWSCognitoDatasetMetadata *> *)listDatasets;
Swift
func listDatasets() -> [AWSCognitoDatasetMetadata]
Return Value
NSArray of AWSCognitoDatasetMetadata
-
List all of the datasets. Returns a AWSTask. The result of this task will be an array of AWSCognitoDatasetMetadata objects.
Declaration
Objective-C
- (nonnull AWSTask *)refreshDatasetMetadata;
Swift
func refreshDatasetMetadata() -> AWSTask
-
Wipe all cached data.
Declaration
Objective-C
- (void)wipe;
Swift
func wipe()
-
Get the default, last writer wins conflict handler
Declaration
Objective-C
+ (nonnull AWSCognitoRecordConflictHandler)defaultConflictHandler;
Swift
class func defaultConflictHandler() -> AWSCognitoRecordConflictHandler
-
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.
Declaration
Objective-C
- (nonnull AWSTask *)registerDevice:(nonnull NSData *)deviceToken;
Swift
func registerDevice(_ deviceToken: Data) -> AWSTask
-
Get the device id Cognito Sync gave this device. nil if device has never been registered
Declaration
Objective-C
+ (nonnull NSString *)cognitoDeviceId;
Swift
class func cognitoDeviceId() -> String
-
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.
Declaration
Objective-C
+ (void)setPushPlatform:(AWSCognitoSyncPlatform)pushPlatform;
Swift
class func setPush(_ pushPlatform: AWSCognitoSyncPlatform)
-
The push platform for push notifications
Declaration
Objective-C
+ (AWSCognitoSyncPlatform)pushPlatform;
Swift
class func pushPlatform() -> AWSCognitoSyncPlatform
-
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
Declaration
Objective-C
- (nonnull AWSTask *)subscribe:(nonnull NSArray<NSString *> *)datasetNames;
Swift
func subscribe(_ datasetNames: [String]) -> AWSTask
-
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
Declaration
Objective-C
- (nonnull AWSTask *)subscribeAll;
Swift
func subscribeAll() -> AWSTask
-
Unsubscribe to a list of datasets. Returns a AWSTask. The result of this task will be a NSArray of AWSCognitoSyncUnsubscribeToDatasetResponse
Declaration
Objective-C
- (nonnull AWSTask *)unsubscribe:(nonnull NSArray<NSString *> *)datasetNames;
Swift
func unsubscribe(_ datasetNames: [String]) -> AWSTask
-
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
Declaration
Objective-C
- (nonnull AWSTask *)unsubscribeAll;
Swift
func unsubscribeAll() -> AWSTask