我使用此代碼來獲取聯繫人列表,然後我想將聯繫人列表存儲到一個數組中,好吧只是第一個名字,如果我得到如何添加所有的名字,然後我將繼續前進,其他屬性也是如此。在NSMutableArray中存儲聯繫人列表
- (void)viewDidLoad {
// Implement viewDidLoad if you need to do additional setup after loading the view.
[super viewDidLoad];
ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book reference object
NSArray *abContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); // get address book contact array
NSInteger totalContacts =[abContactArray count];
for(NSUInteger loop= 0 ; loop < totalContacts; loop++)
{
ABRecordRef record = (ABRecordRef)[abContactArray objectAtIndex:loop]; // get address book record
// NSLog(@"%@,%@,%@",recordIdString,firstNameString,lastNameString);
[myarray addObject:firstNameString];
NSLog(@"%@",[myarray objectAtIndex:1]);
if(ABRecordGetRecordType(record) == kABPersonType) // this check execute if it is person group
{
ABRecordID recordId = ABRecordGetRecordID(record); // get record id from address book record
recordIdString = [NSString stringWithFormat:@"%d",recordId]; // get record id string from record id
firstNameString = (NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty); // fetch contact first name from address book
lastNameString = (NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty); // fetch contact last name from address book
//NSLog(@"%@,%@,%@",recordIdString,firstNameString,lastNameString);
}
}
}
myarray是在.h類中創建的對象NSMutableArray *myarray
。
任何幫助將不勝感激。謝謝。
問題是什麼? – ssteinberg