There's an undocumented API in CNContactStore
- enumeratorForChangeHistoryFetchRequest:error:
I tried to test this method using the following code:
-(void)testChangeHistoryRequest {
CNContactStore *store = [[CNContactStore alloc] init];
[self requestContactsPermissions:store completion:^(BOOL granted) {
if (!granted)
return;
NSData *storeToken = [store currentHistoryToken];
NSLog(@"testChangeHistoryRequest: store token st start - %@", storeToken);
NSError *error;
CNChangeHistoryFetchRequest *req = [[CNChangeHistoryFetchRequest alloc] init];
[req setAdditionalContactKeyDescriptors:@[CNContactGivenNameKey, CNContactFamilyNameKey]];
[req setMutableObjects:YES];
[req setShouldUnifyResults:YES];
[req setStartingToken:storeToken];
CNFetchResult<NSEnumerator<CNChangeHistoryEvent*>*>* res = [store enumeratorForChangeHistoryFetchRequest:req error:&error];
if (res && res.value) {
NSData *token = [res currentHistoryToken];
NSLog(@"token - %@", token);
for (CNChangeHistoryEvent *e in res.value)
NSLog(@"%@ - %@", [e class], e);
NSLog(@"token at end - %@", token);
}
}];
}
What I got is that store.currentHistoryToken
never changes - it starts and ends with nil
value. Also during the iteration, res.currentHistoryToken
is always nil
.
I also tried to initialize [req setStartingToken:storeToken];
with arbitrary data, but this changed nothing (and didn't even fail).
My guess is that this enumeration is not fully implemented.