내 iPad 앱 (Xcode 5, iOS 7, ARC, 스토리 보드)에서 주소록을 읽고 모든 항목을 가져 오려고합니다. 불행히도 다음과 같은 오류가 발생합니다.ABAddressBookCreateWithOptions가 충돌 (인식 할 수없는 선택기)을 발생시킵니다.
SalonBook[2225:a0b] -[__NSCFString count]: unrecognized selector sent to instance 0xb335e70
이것은 내가 작성한 코드이므로 (바퀴를 다시 발명 한 이유는 무엇입니까?).
-(IBAction)importClientData:(UIButton *)sender {
NSMutableArray *allContacts = [[NSMutableArray alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
for(int i = 0;i<ABAddressBookGetPersonCount(addressBook);i++)
{
NSMutableDictionary *aPersonDict = [[NSMutableDictionary alloc] init];
ABRecordRef ref = CFArrayGetValueAtIndex(people, i);
NSString *fullName = (__bridge NSString *) ABRecordCopyCompositeName(ref);
if (fullName) {
[aPersonDict setObject:fullName forKey:@"fullName"];
// collect phone numbers
NSMutableArray *phoneNumbers = [[NSMutableArray alloc] init];
ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++) {
NSString *phoneNumber = (__bridge NSString *) ABMultiValueCopyValueAtIndex(phones, j);
[phoneNumbers addObject:phoneNumber];
}
[aPersonDict setObject:phoneNumbers forKey:@"phoneNumbers"];
// collect emails - key "emails" will contain an array of email addresses
ABMultiValueRef emails = ABRecordCopyValue(ref, kABPersonEmailProperty);
NSMutableArray *emailAddresses = [[NSMutableArray alloc] init];
for(CFIndex idx = 0; idx < ABMultiValueGetCount(emails); idx++) {
NSString *email = (__bridge NSString *)ABMultiValueCopyValueAtIndex(emails, idx);
[emailAddresses addObject:email];
}
[aPersonDict setObject:emailAddresses forKey:@"emails"];
// if you want to collect any other info that's stored in the address book, it follows the same pattern.
// you just need the right kABPerson.... property.
[allContacts addObject:aPersonDict];
}
else {
// Note: I have a few entries in my phone that don't have a name set
// Example one could have just an email address in their address book.
}
}
}
업데이트 : 아무리 내가 (필자는 위의 코드의 몇 가지 변화를 시도했다)를 사용하는 어떤 코드
0 CoreFoundation 0x2e335f53 + 130
1 libobjc.A.dylib 0x3899e6af objc_exception_throw + 38
2 CoreFoundation 0x2e3398e7 + 202
3 CoreFoundation 0x2e3381d3 + 706
4 CoreFoundation 0x2e287598 _CF_forwarding_prep_0 + 24
5 AddressBook 0x2d9274fd ABCCopyUserLanguage + 60
6 AddressBook 0x2d914e3d ABCIsSortDataValid + 28
7 AddressBook 0x2d914d6d ABCCreateAddressBookWithDatabaseDirectoryAndForceInProcessMigrationInProcessLinkingAndResetSortKeys + 1120
8 AddressBook 0x2d928d17 ABAddressBookCreateWithDatabaseDirectory + 74
9 AddressBook 0x2d928e67 ABAddressBookCreateWithOptionsAndPolicy + 146
10 AddressBook 0x2d9290c9 ABAddressBookCreateWithOptions + 88
11 SalonBook 0x000e35db -[CustomerSetupController importClientData:] + 118
12 UIKit 0x30adbf3f + 90
13 UIKit 0x30adbedf + 30
14 UIKit 0x30adbeb9 + 44
15 UIKit 0x30ac7b3f + 374
16 UIKit 0x30adb92f + 590
17 UIKit 0x30adb601 + 528
18 UIKit 0x30ad668d + 832
19 UIKit 0x30aaba25 + 196
20 UIKit 0x30aaa221 + 7096
21 CoreFoundation 0x2e30118b + 14
22 CoreFoundation 0x2e30065b + 206
23 CoreFoundation 0x2e2fee4f + 622
24 CoreFoundation 0x2e269ce7 CFRunLoopRunSpecific + 522
25 CoreFoundation 0x2e269acb CFRunLoopRunInMode + 106
26 GraphicsServices 0x32f37283 GSEventRunModal + 138
27 UIKit 0x30b0ba41 UIApplicationMain + 1136
28 SalonBook 0x000b6335 main + 116
29 libdyld.dylib 0x38ea6ab7 + 2
모두 : 여기에 전체 스택 추적입니다 같은 호출에서 충돌 (-ABAddressBookCreateWithOptions). 여러 예제에서 같은 코드를 복사 했으므로 적어도이 줄이 작동 할 것으로 기대합니다. 그렇지 않아! 왜?
질문을 전체 오류 메시지와 함께 업데이트하십시오. – rmaddy
안녕 Maddy ... 당신이 이것에있어 기쁘다! : D (q 업데이트 됨) SD – SpokaneDude
그 오류는 'ABAddressBookCreateWithOptions'를 호출 한 것이 아닙니다. 문제의 원인이되는 코드 줄은 무엇입니까? 게시 된 코드 중 어느 것도'count' 메소드에 대한 호출을 보여주지 않습니다. 디버거에서 스택 추적을보고 문제의 원인이되는 코드 줄을 확인하십시오. – rmaddy