전화 번호는 이렇게 표시됩니다. 전화 1 개 값 (들) 0 ABMultiValueRef 0x17674380 : $! $ (0x176740e0) - 7124779070 (0x176742a0) IOS :: ABAddressBook에서 연락 전화 번호를 얻는 방법
위의 행에서이 번호 " 7124779070"를 얻는 방법.나는이 코드를 ios7 용으로 사용하고 있습니다. 정확하거나 잘못되었습니다. 제발 sugggest 해주세요.
int i;
ABAddressBookRef contactBook = ABAddressBookCreateWithOptions(NULL, NULL);
NSMutableArray *allData = (NSMutableArray *)(ABAddressBookCopyArrayOfAllPeople(contactBook));
CFIndex contactNum = CFArrayGetCount((__bridge CFArrayRef)(allData));
for (i = 0; i < contactNum; i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex((__bridge CFMutableArrayRef)(allData), i);
NSString* firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSString* lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSString* phonesNum = ABRecordCopyValue(ref, kABPersonPhoneProperty);
// Remove all formatting symbols that might be in both phone number being compared
NSCharacterSet *toExclude = [NSCharacterSet characterSetWithCharactersInString:@"/.()- "];
phonesNum = [[phonesNum componentsSeparatedByCharactersInSet:toExclude] componentsJoinedByString: @""];
NSString *phoneNumber = [[phonesNum componentsSeparatedByCharactersInSet:toExclude] componentsJoinedByString: @""];
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
if (firstName!=nil)
{
[dic setObject:(__bridge id)(firstName) forKey:@"firstName"];
}
if (lastName !=nil) {
[dic setObject:(__bridge id)(lastName) forKey:@"lastName"];
}
if (phonesNum!=nil) {
[dic setObject:(__bridge id)(phonesNum) forKey:@"phonesNum"];
}
[arr_Contacts addObject:dic];
NSLog(@"First name %@", firstName);
NSLog(@"Last Name %@", lastName);
NSLog(@"Phone %@", phonesNum);
}
첫 번째 전화 번호 만 사용 하시겠습니까? – Rob
[주소록 프로그래밍 가이드] (https://developer.apple.com/Library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html)를 읽어 보셨습니까? 당신은 그렇지 않으면해야합니다. 대부분의 쟁점에 대답하지 않더라도, 당신이 묻는 것은 기본적인 코딩이 전부가 아닙니다.답변에 코드를 복사하여 붙여 넣을 수는 있지만 맹목적으로 수행하면 더 많은 문제 (혼동)가 발생합니다. – n00bProgrammer
가능한 복제본 http://stackoverflow.com/a/23418263/1271826 – Rob