How to get notified in contact changed event in IOS?
In iOS it could be done using -
Register the external change call back notifier-
ABAddressBookRef ntificationaddressbook = ABAddressBookCreate();
ABAddressBookRegisterExternalChangeCallback(ntificationaddressbook, MyAddressBookExternalChangeCallback, self);
Implement the call back -
void MyAddressBookExternalChangeCallback (ABAddressBookRef ntificationaddressbook,CFDictionaryRef info,void *context)
{
// called when there is any change in AddressBook
}
For more details you can refer this link-
Detect what was changed from ABAddressBookRegisterExternalChangeCallback
How do I know that the contacts have been modified, if the application was not active on iOS?
I made the following functions for my task
@objc private func matchingContacts() {
if isSuccessContactUploading {
contactManager.matchingContacts(notMatch: { [weak self] in
guard let _self = self else { return }
debugPrint("matchingContacts != equals")
_self.isSuccessContactUploading = false
_self.syncContacts()
})
}
}
These functions are in ContactManager
func matchingContacts(notMatch: (() -> Void)?) {
getContacts { (contacts, error) in
if error == nil {
debugPrint("contacts count", contacts.count)
self.getContactsDictionaryFromCache(contacts, notMatch: {
notMatch?()
})
}
}
}
private func getContactsDictionaryFromCache(_ contacts: [CNContact], notMatch: (() -> Void)?) {
var isMatching = true
for contact in contacts {
let key = contact.identifier
do {
let cache = try Cache<NSDictionary>(name: "Contacts")
if let contactDictionary = cache[key] {
if !contactDictionary.isEqual(to: contact.dictionary) {
debugPrint("contactDictionary not matching")
isMatching = false
}
} else {
debugPrint("contactDictionary isn't here")
isMatching = false
}
} catch {
debugPrint(error.localizedDescription)
isMatching = false
}
}
if !isMatching {
notMatch?()
}
cacheContacts(contacts)
}
private func cacheContacts(_ contacts: [CNContact]) {
for contact in contacts {
let contactDictionary = contact.dictionary as NSDictionary
let key = contact.identifier
do {
let cache = try Cache<NSDictionary>(name: "Contacts")
cache[key] = contactDictionary
} catch {
debugPrint(error.localizedDescription)
}
}
}
Related Topics
Unnotificationattachment with Uiimage or Remote Url
Launch Other Application Without Url Schema in Iphone
Uiimagepicker Cameraoverlayview Appears on Retake Screen
Prevent Dispatch_After() Background Task from Being Executed
How to Use Unsafemutablepointer in Swift 3
Alamofire Fire Variable Type Has No Subscript Members
Setting Multiple Times for Notifications in Swift
How to Tell What Profile/Signing Certificate Was Used to Sign .Ipa
Programmatically Fire Button Click Event
How to Send Email Using Mfmailcomposeviewcontroller in Simulator
Simulate Universal Gravitation for Two Sprite Kit Nodes
Nsnotificationcenter Swift 3.0 on Keyboard Show and Hide
Differentiate Between Screen Lock and Home Button Press on iOS7
After Updating to Xcode 10.2: Invalid Toolchain Error When Trying to Submit App to App Store