I had a problem saving the RecordID to NSUserDefault and then retrieving it and the list as a table.
in the method:
func peoplePickerNavigationController( peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecordRef!) {
i Enter the following code to save the ID of the selected person
let contactID: ABRecordID = ABRecordGetRecordID(firstName)
if contactID != kABRecordInvalidID{
var numberID: NSNumber = NSNumber(int: contactID)
println(numberID.integerValue)
contatosRecentes.append(numberID.integerValue)
}
NSUserDefaults.standardUserDefaults().setObject(contatosRecentes, forKey: "rf")
contatosRecentes -
var contatosRecentes = [Int]()
I checked the code and saved the id. The problem is when I try to get the name of the person using the code:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
var recordID: Int = contatosRecentes[indexPath.row]
var numberID: ABRecordID = NSNumber(integer: recordID).intValue
var errorCM: UnsafePointer<Unmanaged<CFError>?> = nil
var addressBook = ABAddressBookCreateWithOptions(nil, errorCM)
var addressBookRef: ABAddressBookRef? = Unmanaged<NSObject>.fromOpaque(addressBook.toOpaque()).takeUnretainedValue()
var person = ABAddressBookGetPersonWithRecordID(addressBookRef, numberID)
var personRef: ABRecordRef = Unmanaged<NSObject>.fromOpaque(person.toOpaque()).takeUnretainedValue() as ABRecordRef
var personName = ABRecordCopyValue(personRef, kABPersonFirstNameProperty)
var firstName: ABRecordRef = Unmanaged.fromOpaque(personName.toOpaque()).takeUnretainedValue() as NSString as ABRecordRef
cell.textLabel.text = firstName as? String
cell.imageView.image = UIImage(named: "img_profile.png")
cell.imageView.layer.cornerRadius = 21
cell.imageView.clipsToBounds = true;
return cell
}
The problem is the variable firstName is Empty.
ps .: I have many contacts in the iPhone simulator
Thank!
source
share