이름과 전화 번호부에 액세스하려고 시도하면서 며칠 동안 고통을 겪고 있습니다. 모두 실패했습니다. 테스트 응용 프로그램에서 성공적으로 작동하는 다음 코드를 사용하지만 프로젝트 작업에 추가하면 작동하지 않습니다. 변수 "granted"는 값이 "false"이고 오류 "Access Failure"가 발생합니다. 그럼에도 불구하고, 개인 정보 보호 설정에서 ... 액세스 나는 오히려 이상한 행동에 대한 답을 찾을 수 없습니다 오랫동안이 을 ... 수 있도록 슬라이더를 표시되지 않습니다 응용 프로그램에서 전화 번호부에 액세스 할 수 없습니다.
내가 어떤 도움을 감사하게 될 것입니다!`
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted == YES) {
NSMutableArray *contacts = [NSMutableArray array];
NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey];
NSString *containerId = store.defaultContainerIdentifier;
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
NSError *error;
NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
if (error) {
NSLog(@"error fetching contacts %@", error);
} else {
for (CNContact *contact in cnContacts) {
TSContact *newContact = [[TSContact alloc] init];
newContact.firstName = contact.givenName;
newContact.lastName = contact.familyName;
UIImage *image = [UIImage imageWithData:contact.imageData];
newContact.image = image;
for (CNLabeledValue *label in contact.phoneNumbers) {
NSString *phone = [label.value stringValue];
if ([phone length] > 0) {
[contacts addObject:phone];
}
}
}
}
} else {
NSLog(@"Error = %@", error.localizedDescription);
}
}];
앱의 배포 대상은 무엇입니까 (iOS 버전 6.0을 타겟팅합니까)? – theFool
info.plist에'Privacy - Contacts Usage Description' 키를 추가 했습니까? iOS 6.0 이상에서 지원됩니다. –
iOS 8과 9가 여전히 작동하지 않습니다. –