CKFetchRecordChangesOperation - moreComing
changesOperation.fetchRecordChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken, NSData *clientChangeTokenData, NSError *operationError){
//encode and save token
NSData *encodedServerChangeToken = [NSKeyedArchiver archivedDataWithRootObject:serverChangeToken];
[[NSUserDefaults standardUserDefaults] setObject:encodedServerChangeToken forKey:fetchToken];
[[NSUserDefaults standardUserDefaults] synchronize];
//handle more - **this causes a retain cycle**
if(changesOperation.moreComing){
}
};
Hi just wondering, in the fetchRecordChangesCompletionBlock file, the docs say:
If the server cannot deliver all modified results with this operational object, it sets this property to YES before executing the block in the fetchRecordChangesCompletionBlock property. To retrieve the remaining changes, create a new CKFetchRecordChangesOperation object using the change token returned by the server.
The above code creates a save loop, so how should this be handled and can the same set of completed blocks be used when recreating the operation?
+3
source to share
1 answer
You must define a weak change like this
__weak CKFetchNotificationChangesOperation *weakChangesOperation = changesOperation;
changesOperation.fetchRecordChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken, NSData *clientChangeTokenData, NSError *operationError){
...
if(weakChangesOperation.moreComing){
}
+4
source to share