Closed vicky1787 closed 8 years ago
1) Unfortunately AddressBook.framework
doesn't have built-in way to get changed contacts. But you can try to save date of last fetch. And after external changes detected fetch contacts with filter like "contact modification date > date of last fetch".
2) Use loadContactByRecordID:completion:
method.
3-4) Sorry, don't have a plans to implement such functional. But we'll keep in mind it.
Hope it helps.
Thanks I did exactly as suggest given to me in my previous logic. But can you guide me as to how easy and optimized way I can detect the contact that are there in my saved list but not in the phone contacts.
Currently I am doing refer check for all saved records against the master records given by library. Any nor suggestions.
Thanks Vicky
On Wednesday, 2 December 2015, Alexey Belkevich notifications@github.com wrote:
1) Unfortunately AddressBook.framework doesn't have built-in way to get changed contacts. But you can try to save date of last fetch. And after external changes detected fetch contacts with filter like "contact modification date > date of last fetch".
2) Use loadContactByRecordID:completion: method.
3-4) Sorry, don't have a plans to implement such functional. But we'll keep in mind it.
Hope it helps.
— Reply to this email directly or view it on GitHub https://github.com/Alterplay/APAddressBook/issues/109#issuecomment-161046925 .
Sent from my iPhone
Please, share your code
[self.addressBook loadContactsOnQueue:queue completion:^(NSArray<APContact *> * _Nullable contacts, NSError * _Nullable error) // [self.addressBook loadContacts:^(NSArray *contacts, NSError *error)
{
NSDate *latestModifedContactDate = nil;
//some link contacts check
if(!tempLinkedContacts)
[tempLinkedContacts removeAllObjects];
else
tempLinkedContacts = [[NSMutableArray alloc] init];
int counter = 0;
NSMutableArray *syncingcontacts = [[NSMutableArray alloc] init];
for (APContact *apContactObject in contacts) {
if(apContactObject.linkedRecordIDs.count > 0)
{
//check if any of the link contacts is already in the DB then dont add this contacts
BOOL isLinkedContactsInDb = [[CLBizManager sharedManager] checkIdContactExistithABIds:apContactObject.linkedRecordIDs managedContext:privateContext];
if(!isLinkedContactsInDb)
{
DLog(@"Contact Added[L]:\t[%@]|[%@]",apContactObject.name.compositeName,apContactObject.recordID);
//ADD Contact to DB
//Loop to check if valid contact and then send to server using the array with this item
}
}
else
{
//Straight update/add the contact
//ADD Contact to DB
NSLog(@"Contact Added[S]:\t[%@]|[%@]",apContactObject.name.compositeName,apContactObject.recordID);
//Loop to check if valid contact and then send to server using the array with this item
}
if(!latestModifedContactDate || [latestModifedContactDate compare:apContactObject.recordDate.modificationDate] == NSOrderedAscending)
latestModifedContactDate = apContactObject.recordDate.modificationDate;
[[NSNotificationCenter defaultCenter] postNotificationName:kContactLoadProgressNotificationKey object:[NSDictionary dictionaryWithObjects:@[[NSNumber numberWithInt:counter],[NSNumber numberWithInteger:[contacts count]]] forKeys:@[kContactNoKey,kContactTotalCountKey]]];
counter++;
}
//Store the loaded contacts latest one in the list time to user defaults
//Save the DB using private context used
}]; //LoadContacts end
1) You should create property to store last contacts load date and set it in loadContacts:
method
__weak typeof(self) weakSelf = self;
[self.addressBook loadContactsOnQueue:queue completion:^(NSArray *contacts, NSError *error)
{
weakSelf.lastLoadDate = [NSDate date];
// your code here
2) You should set filter block like this
__weak typeof(self) weakSelf = self;
self.addressBook.filterBlock = ^BOOL(APContact *contact)
{
return self.lastLoadDate != nil ? [contact.recordDate.modificationDate comapre:weakSelf.lastLoadDate] == NSOrderedAscending : YES;
};
3) Add observation block
__weak typeof(self) weakSelf = self;
[addressBook startObserveChangesWithCallback:^
{
[self reloadContacts]
}];
So, at first time it will load all contacts. But then it'll load only modified or newly added contacts
Thanks for the information, I'll definitely try this. By the way a great library implemented specially the upgrades and pods that I track everything for new features. Appreciate your help. RegardsVicky
Sent from Outlook Mobile
On Tue, Jan 5, 2016 at 5:19 AM -0800, "Alexey Belkevich" notifications@github.com wrote:
1) You should create property to store last contacts load date and set it in loadContacts: method
__weak typeof(self) weakSelf = self; [self.addressBook loadContactsOnQueue:queue completion:^(NSArray contacts, NSError error) { weakSelf.lastLoadDate = [NSDate date]; // your code here
2) You should set filter block like this
__weak typeof(self) weakSelf = self; self.addressBook.filterBlock = ^BOOL(APContact *contact) { return self.lastLoadDate != nil ? [contact.recordDate.modificationDate comapre:weakSelf.lastLoadDate] == NSOrderedAscending : YES; };
3) Add observation block
__weak typeof(self) weakSelf = self; [addressBook startObserveChangesWithCallback:^ { [self reloadContacts] }];
So, at first time it will load all contacts. But then it'll load only modified or newly added contacts
— Reply to this email directly or view it on GitHub.
Feel free to reopen this issue if you find some problems.
Can we have the following method as this is great library for our requirements.
1) startObserveChangesWithCallback like method to give the contacts array that are modified/deleted only currently its a void parameter block hence need to reiterate the current records stored in our db with the master list and vicerversa to find the modified records and then delete the ones not found in IOS Contacts but still stored in our DB previously.
2) Fetch the contact with respect to address book ID passed.
3) Add contacts simplified function to implement Add New / Add to Existing contact feature.
4) We wanted to show the progress for contacts being taken from contacts IOS to our Core-Data in % fashion. But the callback takes time and return all at once. Can we have something that can help us in progressive way so we keep user engagement more to know whats the current status.
These 4 features will really be an awesome help for this library.