I'm currently working on an app, which take the all the address book contacts information and store it core data / Realm. But it happen only once, but how to capture when user add new contact / delete / update on the phone contact list.
Asked
Active
Viewed 230 times
1 Answers
0
when user add or update the phonebook, you can capture the changes through external call back methods mentioned below.
IOS9
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CNcontactDidChange:)name:CNContactStoreDidChangeNotification object:nil];
IOS8
ABAddressBookRegisterExternalChangeCallback(book,MyAddressBookExternalChangeCallback,(__bridge void *)(self));
Then use the method mentioned below to update Realm ,
+ (instancetype)createOrUpdateInRealm:(RLMRealm *)realm withValue:(id)value;
Vijay Karthik
- 457
- 4
- 6
-
Yeah, but how to get the exact contact ID which changed the contact list ? – Mudith Chathuranga Silva Mar 02 '16 at 12:35
-
You don't get info about that, so that you need to refetch all contacts you are interested in. – marius Mar 02 '16 at 16:45
-
Refer this link .. http://stackoverflow.com/questions/17440115/detect-what-was-changed-from-abaddressbookregisterexternalchangecallback – Vijay Karthik Mar 03 '16 at 04:08