iOS app does not show alert for permission of Addressbook access -


i working on app required show contacts.

it working fine on xcode 6.2. when run project on xcode 7.2, not asking permission alert.

i write following method permission.

-(void)requestaddressbookaccess {     contactsviewcontroller * __weak weakself = self;      abaddressbookrequestaccesswithcompletion(self.addressbook, ^(bool granted, cferrorref error)                                              {                                                  if (granted)                                                  {                                                      dispatch_async(dispatch_get_main_queue(), ^{                                                          [weakself accessgrantedforaddressbook];                                                       });                                                  }                                              }); } 

it give granted = false , error = nil.

any appreciated.

in ios 9 have use contacts framework addressbook framework depricated

-(void)addressbookauthorizationusingcontacts {     //#import #import <contacts/contacts.h>     // request authorization address book using contacts    cncontactstore *store = [[cncontactstore alloc] init];    [store requestaccessforentitytype:cnentitytypecontacts completionhandler:^(bool granted, nserror * _nullable error) {     if (granted == yes) {         //keys fetching properties         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 {             nsstring *phone;             nsstring *fullname;             nsstring *firstname;             nsstring *lastname;             uiimage *profileimage;             nsmutablearray *contactnumbersarray = [[nsmutablearray alloc]init];             nsmutablearray *contactsarray = [[nsmutablearray alloc]init];             (cncontact *contact in cncontacts) {                 // copy data custom contacts class.                 firstname = contact.givenname;                 lastname = contact.familyname;                 if (lastname == nil) {                     fullname=[nsstring stringwithformat:@"%@",firstname];                 }else if (firstname == nil){                     fullname=[nsstring stringwithformat:@"%@",lastname];                 }                 else{                     fullname=[nsstring stringwithformat:@"%@ %@",firstname,lastname];                 }                 uiimage *image = [uiimage imagewithdata:contact.imagedata];                 if (image != nil) {                     profileimage = image;                 }else{                     profileimage = [uiimage imagenamed:@"person-icon.png"];                 }                 (cnlabeledvalue *label in contact.phonenumbers) {                     phone = [label.value stringvalue];                     if ([phone length] > 0) {                         [contactnumbersarray addobject:phone];                     }                 }                 nsdictionary* persondict = [[nsdictionary alloc] initwithobjectsandkeys: fullname,@"fullname",profileimage,@"userimage",phone,@"phonenumbers", nil];                 [contactsarray addobject:persondict];                 nslog(@"the contactsarray - %@",contactsarray);             }             dispatch_async(dispatch_get_main_queue(), ^{                 [tableviewcontacts reloaddata];             });         }     } }]; } 

the output results are

the contactsarray - (     {     fullname = "john appleseed"; },     {     fullname = "kate bell"; },     {     fullname = "anna haro"; },     {     fullname = "daniel higgins"; },     {     fullname = "david taylor"; },     {     fullname = "hank zakroff"; } ) 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -