I have created a simple contact app using Apple's addressbook and with the following delegates ABNewPersonViewControllerDelegate,ABPeoplePickerNavigationControllerDelegate and ABPersonViewControllerDelegate and it has the features: Create, Edit and Delete contact. Now I want to add an option through which all my Created contacts along with the phone numbers will be imported on a text file. This is my code:
-(void)fetchContacts
{
addressBooks =ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBooks);
for (CFIndex i = 0; i < CFArrayGetCount(people); i++)
{
person12 = CFArrayGetValueAtIndex(people, i);
NSString *tweet=[[NSString stringWithFormat:@"%@",(__bridge_transfer NSString *)ABRecordCopyValue(person12, kABPersonFirstNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if(CFBridgingRelease(ABRecordCopyValue(person12,kABPersonLastNameProperty))!=NULL)
{
tweet=[tweet stringByAppendingString:@" "];
tweet=[tweet stringByAppendingString:[[NSString stringWithFormat:@"%@",(__bridge_transfer NSString *)ABRecordCopyValue(person12, kABPersonLastNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
}
if(CFBridgingRelease(ABRecordCopyValue(person12,kABPersonFirstNameProperty))!=NULL)
{
tweet=[tweet stringByAppendingString:@" ---> "];
tweet=[tweet stringByAppendingString:[[NSString stringWithFormat:@"%@",(__bridge_transfer NSString *)ABRecordCopyValue(person12, kABPersonPhoneProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
}
NSLog(@"%@",tweet);
NSString* documentPlistPath = [[NSBundle mainBundle] pathForResource:@"Contacts" ofType:@"txt"];
[tweet writeToFile:documentPlistPath atomically:NO encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",documentPlistPath);
}
CFBridgingRelease(people);
}
I have two problems here now:
1) On NSLog, the tweet contains all value but in following format like: FirstName LastName ---> ABMultiValueRef 0x6c26760 with 1 value(s) 0: $!!$ (0x6c26b60) - PhoneNumber (0x6c26b80)
I need it in this format FirstName LastName ---> PhoneNumber
2)The Contact.txt file is not get populated. On NSLog Path is correct. Please advice whats wrong here.