From d9149b6b2c0800f676d6fd049501b6ae8fc0554b Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Thu, 21 Sep 2017 10:15:44 +0200 Subject: [PATCH] fetching contacts is not required to ask for contact permission --- Classes/Utils/FastAddressBook.m | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index e7932a6e5..e9cf29f9d 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -123,33 +123,12 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info CNEntityType entityType = CNEntityTypeContacts; if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusNotDetermined) { CNContactStore * contactStore = [[CNContactStore alloc] init]; + LOGD(@"CNContactStore requesting authorization"); [contactStore requestAccessForEntityType:entityType completionHandler:^(BOOL granted, NSError * _Nullable error) { - if(granted){ - NSError* contactError; - store = [[CNContactStore alloc]init]; - [store containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers: @[store.defaultContainerIdentifier]] error:&contactError]; - NSArray * keysToFetch =@[CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey]; - CNContactFetchRequest * request = [[CNContactFetchRequest alloc]initWithKeysToFetch:keysToFetch]; - BOOL success = [store enumerateContactsWithFetchRequest:request error:&contactError usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop){}]; - if(success) { - LOGD(@"CNContactStore successfully synchronized"); - } - } + LOGD(@"CNContactStore authorization granted"); }]; } else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) { - NSError* contactError; - store = [[CNContactStore alloc]init]; - [store containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers: @[store.defaultContainerIdentifier]] error:&contactError]; - NSArray * keysToFetch =@[CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey]; - CNContactFetchRequest * request = [[CNContactFetchRequest alloc]initWithKeysToFetch:keysToFetch]; - __block int number_of_contact=0; - LOGD(@"CNContactStore synchronizing"); - BOOL success = [store enumerateContactsWithFetchRequest:request error:&contactError usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop){ - number_of_contact++; - }]; - if(success) { - LOGD(@"CNContactStore [%i] contacts successfully synchronized",number_of_contact); - } + LOGD(@"CNContactStore authorization granted"); } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAddressBook:) name:CNContactStoreDidChangeNotification object:nil]; }