我可以从 iphone sdk 中提取联系人列表的名字和姓氏,但是我无法从中获取电话号码。如果我尝试其他方式,我会收到错误消息,而我使用电话号码获取其他内容的常用方式是代码的详细信息:
- (IBAction)buttonmessage {
ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book reference object
NSArray *abContactArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); // get address book contact array
NSInteger totalContacts = [abContactArray count];
for(NSUInteger loop= 0 ; loop < totalContacts; loop++)
{
ABRecordRef record = (__bridge ABRecordRef)[abContactArray objectAtIndex:loop]; // get address book record
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 = (__bridge NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty); // fetch contact first name from address book
lastNameString = (__bridge NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty); // fetch contact last name from address book
NSString *phnumber = (__bridge NSString *)ABRecordCopyValue(record, kABPersonPhoneProperty);
myArray2 = [NSArray arrayWithObjects:firstNameString,lastNameString,phnumber,nil];
NSString *m12=[NSString stringWithFormat:@"%@,%@,%@",[myArray2 objectAtIndex:0],[myArray2 objectAtIndex:1],[myArray2 objectAtIndex:2]];
}
输出:
Abdullah,Rashed,ABMultiValueRef 0x80426a0 with 1 value(s)
0: _$!<Mobile>!$_ (0x8042da0) - 0550979691 (0x8042dc0)
2012-05-07 14:43:06.670 Firstphase[2914:207] Hussain,Mahmood,ABMultiValueRef 0x80442d0 with 1 value(s)
0: _$!<Mobile>!$_ (0x8044290) - 055979896 (0x80442b0)
2012-05-07 14:43:06.671 Firstphase[2914:207] Nasir,Jilaani,ABMultiValueRef 0x8046070 with 1 value(s)
0: _$!<Mobile>!$_ (0x8046000) - 055982391 (0x8046020)
2012-05-07 14:43:06.673 Firstphase[2914:207] Ghulam,Basith,ABMultiValueRef 0x8046850 with 1 value(s)
0: _$!<Mobile>!$_ (0x8046810) - 055871943 (0x8046830)
但是,如果您仔细查看,我可以在没有任何额外内容的情况下获得名字和姓氏。但我无法以同样的方式获取电话号码。