0中授予访问电话通讯簿的权限

0中授予访问电话通讯簿的权限

本文介绍了如何在ios 10.0中授予访问电话通讯簿的权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已添加到.plist NSContactsUsageDescription

I added to the .plist NSContactsUsageDescription

不起作用-设备版本:10.0

KTSContactsManager *addressBookManager = [KTSContactsManager sharedManager];
addressBookManager.delegate = self;
addressBookManager.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES]];

if ([isAddressBookTaken isEqualToString:@"false"]) {
    [addressBookManager importContacts:^(NSArray *contacts) {
        [EBLogger logWithTag:@"TBLContactManager" withBody:@"importContacts"];

        DLPhoneBook *phoneBook = [DLPhoneBook new];
        NSMutableArray *mutableArray = [NSMutableArray new];

        for (int i = 0; i < contacts.count; ++i) {
            NSDictionary *record = [contacts objectAtIndex:i];
            NSError *err = nil;
            DLContactRecord *contactRecord = [[DLContactRecord alloc] initWithDictionary:record error:&err];

            NSLog(@" %@ %@ %@ '",contactRecord.firstName, contactRecord.lastName, contactRecord.id);
         }
    }

推荐答案

您必须在plist中添加信息列表,

You have to add information list in your plist,

这是各种隐私的信息清单.

Here is information plist for various privacy.

在plist中添加所需的隐私,然后再次检查.

Add Privacy that you want in you plist and check again.

并将此代码添加到您的文件中,

and ADD this code in your file,

- (void)viewDidLoad {
    [super viewDidLoad];
    contactList=[[NSMutableArray alloc] init];
    ABAddressBookRef m_addressbook = ABAddressBookCreate();

    if (!m_addressbook) {
        NSLog(@"opening address book");
    }

    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
    CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

    for (int i=0;i &lt; nPeople;i++) {
        NSMutableDictionary *dOfPerson=[NSMutableDictionary dictionary];

        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);

        //For username and surname
        ABMultiValueRef phones =(NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty);
        CFStringRef firstName, lastName;
        firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
        lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);
        [dOfPerson setObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName] forKey:@"name"];

        //For Email ids
        ABMutableMultiValueRef eMail  = ABRecordCopyValue(ref, kABPersonEmailProperty);
        if(ABMultiValueGetCount(eMail) &gt; 0) {
            [dOfPerson setObject:(NSString *)ABMultiValueCopyValueAtIndex(eMail, 0) forKey:@"email"];

        }

        //For Phone number
        NSString* mobileLabel;
        for(CFIndex i = 0; i &lt; ABMultiValueGetCount(phones); i++) {
            mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
            if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
            {
                [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];
            }
            else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel])
            {
                [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];
                break ;
            }

        [contactList addObject:dOfPerson];
        CFRelease(ref);
        CFRelease(firstName);
        CFRelease(lastName);
    }
    NSLog(@"array is %@",contactList);
    }
}

有关它的更多信息,请访问

For more about it visit,

http://sugartin.info/2011/09/07/从iphone-address-book-in-contacts中获取信息/

希望它会对您有所帮助.

Hope it will help you.

这篇关于如何在ios 10.0中授予访问电话通讯簿的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:05