I want to check if the number registered on my App and stored on my server are on the device where the app is running. I tried but I really can't go forward from here:
In my class I have declared:
var chatMatesArray: NSMutableArray = NSMutableArray()
var contactsName: NSMutableArray = NSMutableArray()
var users: NSMutableArray = NSMutableArray()
var phoneNumbers: NSMutableArray = NSMutableArray()
And in my viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
//I already have the permission to check AddressBook
var allNumbers: [AnyObject] = []
let adbk : ABAddressBook? = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()
let people = ABAddressBookCopyArrayOfAllPeople(adbk).takeRetainedValue() as NSArray as [ABRecord]
for person in people {
let phones: ABMultiValueRef = ABRecordCopyValue(person, kABPersonPhoneProperty).takeRetainedValue()
for j in 0..<ABMultiValueGetCount(phones) {
let phone: String = ABMultiValueCopyValueAtIndex(phones, j).takeRetainedValue() as! String
allNumbers.append(phone)
self.phoneNumbers.addObject(allNumbers)
}
}
}
Then I have a func that retrieve number from my server, I store them into the array chatMatesArray and then I try to do:
let set1 = Set(arrayLiteral: self.chatMatesArray)
let set2 = Set(arrayLiteral: self.phoneNumbers)
self.users.addObject(set2.intersect(set1))
This would check numbers that are both on my server and on the addressBook, right? But then how can I go back from that number to their owner full name so that I can show in a UITableView?
Thanks in advance for your help.