暫無描述

AWSCognitoDataset.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // Copyright 2014-2016 Amazon.com,
  3. // Inc. or its affiliates. All Rights Reserved.
  4. //
  5. // Licensed under the Amazon Software License (the "License").
  6. // You may not use this file except in compliance with the
  7. // License. A copy of the License is located at
  8. //
  9. // http://aws.amazon.com/asl/
  10. //
  11. // or in the "license" file accompanying this file. This file is
  12. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. // CONDITIONS OF ANY KIND, express or implied. See the License
  14. // for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. #import <Foundation/Foundation.h>
  18. #import "AWSCognitoHandlers.h"
  19. @class AWSCognitoRecord;
  20. @class AWSTask;
  21. /**
  22. An object that encapsulates the dataset metadata.
  23. */
  24. @interface AWSCognitoDatasetMetadata : NSObject
  25. /**
  26. The name of this dataset
  27. */
  28. @property (nonatomic, readonly) NSString *name;
  29. /**
  30. The last sync count known on the client device.
  31. */
  32. @property (nonatomic, readonly) NSNumber *lastSyncCount;
  33. /**
  34. The creation date of the dataset on the remote store.
  35. */
  36. @property (nonatomic, readonly) NSDate *creationDate;
  37. /**
  38. The amount of storage on the remote store this dataset uses.
  39. */
  40. @property (nonatomic, readonly) NSNumber *dataStorage;
  41. /**
  42. The id of the last device to modify this dataset.
  43. */
  44. @property (nonatomic, readonly) NSString *lastModifiedBy;
  45. /**
  46. The date this dataset was last modified
  47. */
  48. @property (nonatomic, readonly) NSDate *lastModifiedDate;
  49. /**
  50. The number of records in this dataset on the remote store.
  51. */
  52. @property (nonatomic, readonly) NSNumber *numRecords;
  53. /**
  54. Returns true if this dataset has been cleared locally, but not synchronized.
  55. */
  56. - (BOOL)isDeleted;
  57. @end
  58. /**
  59. An object that encapsulates the dataset. The dataset is the unit of sync
  60. for Amazon Cognito.
  61. */
  62. @interface AWSCognitoDataset : AWSCognitoDatasetMetadata
  63. /**
  64. A conflict resolution handler that will receive calls when there is a
  65. conflict during a sync operation. A conflict will occur when both remote and
  66. local data have been updated since the last sync time.
  67. When not explicitly set, we will use the default conflict resolution of
  68. 'last writer wins', where the data most recently updated will be persisted.
  69. */
  70. @property (nonatomic, copy) AWSCognitoRecordConflictHandler conflictHandler;
  71. /**
  72. A deleted dataset handler. This handler will be called during a synchronization
  73. when the remote service indicates that a dataset has been deleted.
  74. Returning YES from the handler will cause the service to recreate the dataset
  75. on the remote on the next synchronization. Returning NO or leaving this property
  76. nil will cause the client to delete the dataset locally.
  77. */
  78. @property (nonatomic, copy) AWSCognitoDatasetDeletedHandler datasetDeletedHandler;
  79. /**
  80. A merged dataset handler. This handler will be called during a synchronization
  81. when the remote service indicates that other datasets should be merged with this one.
  82. Merged datasets should be fetched, their data overlayed locally and then removed.
  83. Failing to implement this handler will result in merged datasets remaining on the
  84. service indefinitely.
  85. */
  86. @property (nonatomic, copy) AWSCognitoDatasetMergedHandler datasetMergedHandler;
  87. /**
  88. The number of times to attempt a synchronization before failing. Defaults to
  89. to the value on the AWSCognito client that opened this dataset.
  90. */
  91. @property (nonatomic, assign) uint32_t synchronizeRetries;
  92. /**
  93. Only synchronize if device is on a WiFi network. Defaults to
  94. to the value on the AWSCognito client that opened this dataset.
  95. */
  96. @property (nonatomic, assign) BOOL synchronizeOnWiFiOnly;
  97. /**
  98. Sets a string object for the specified key in the dataset.
  99. */
  100. - (void)setString:(NSString *) aString forKey:(NSString *) aKey;
  101. /**
  102. Returns the string associated with the specified key.
  103. */
  104. - (NSString *)stringForKey:(NSString *) aKey;
  105. /**
  106. Synchronize local changes with remote changes on the service. First it pulls down changes from the service
  107. and attempts to overlay them on the local store. Then it pushes any local updates to the service. If at any
  108. point there is a conflict, conflict resolution is invoked. No changes are pushed to the service until
  109. all conflicts are resolved.
  110. */
  111. - (AWSTask *)synchronize;
  112. /**
  113. Attempts to synchronize when device has connectivity. First it checks connectivity, if device is online
  114. immediately invokes synchronize and returns the AWSTask associated with the attempt. If the device is offline,
  115. schedules a synchronize for the next time the device comes online and returns a AWSTask with a nil result.
  116. The scheduled synchronize is only valid for the lifecycle of the dataset object. The data will not be synchronized
  117. if the app is exited before connectivity is regained. If you want to be notified when events occur during the
  118. scheduled synchronize, you must add observers of the notifications found in AWSCognito
  119. */
  120. - (AWSTask *)synchronizeOnConnectivity;
  121. /**
  122. Subscribes this dataset to push notifications
  123. @return AWSTask with nil result. task.error will contain any errors.
  124. */
  125. - (AWSTask *)subscribe;
  126. /**
  127. Unsubscribes this dataset to push notifications
  128. @return AWSTask with nil result. task.error will contain any errors.
  129. */
  130. - (AWSTask *)unsubscribe;
  131. /**
  132. Returns all of the records in the dataset. Will return deleted records.
  133. @return NSArray of AWSCognitoRecord objects
  134. */
  135. - (NSArray<AWSCognitoRecord *> *)getAllRecords;
  136. /**
  137. Returns all the key value pairs in the dataset, ignore any deleted data.
  138. @return NSDictionary of all key value pairs. Contains no metadata.
  139. */
  140. - (NSDictionary<NSString *, NSString *> *)getAll;
  141. /**
  142. Remove a record from the dataset.
  143. @param aKey the key to remove
  144. */
  145. - (void)removeObjectForKey:(NSString *) aKey;
  146. /**
  147. Returns the record associated with the specified key.
  148. @param aKey the key to return
  149. @return AWSCognitoRecord for this particular record. Will return nil if record does not exist.
  150. */
  151. - (AWSCognitoRecord *)recordForKey:(NSString *) aKey;
  152. /**
  153. Clear this dataset locally. Dataset will not be removed from the service until the next synchronize call.
  154. */
  155. - (void) clear;
  156. /**
  157. Returns the size in bytes for this dataset.
  158. */
  159. - (long) size;
  160. /**
  161. Returns the size in bytes for the specified key.
  162. @param aKey the key to check
  163. */
  164. - (long) sizeForKey:(NSString *) aKey;
  165. @end