Hi I'm currently working on a project for a customer where i need to access the phones contacts.
I managed to ask for the Permission to access the contacts and i m handling the two different states (granted, denied). Apparently the customer wants the following workflow:
- hit an add button
- ask for permission
- granted: performs a segue to a tablewview with all contacts listed
- denied: performs a segue to a differnt view and keeps asking on the inital button hit to grant access to the contacs
I ve managed the complete flow and fetched the complete data. No i m stuck with two problems:
- I can't get the the ask for permission alertview pop up again (from my understanding the user needs to set this in the Application Settings ->App privacy settings). Is this correct?
- It appears that if access is granted for the first time and i perform a segue the tableview is empty because the data array is nil (i can't figure out why).
- (void)addButtonTouched { [self.addressBook accessAddressBook]; [self.activityView startActivityViewWithMessage:@"Wait a second"]; if (access) { self.contactsArray = [self.addressBook getAllContacts]; if (self.contactsArray.count != 0) { [self performSegueWithIdentifier:@"addEntrySegue" sender:self]; } else { [self performSegueWithIdentifier:@"noContactsSegue" sender:self]; } }
Am I pushing to soon to the next ViewController to fill self.contactsArray
?
My other approach was to send a Notifictaion to my rootViewController when the access was granted and then perform the segue. This was the closest result i could get, but the ViewController push delayed aber 8-10 seconds.
> - (void)receivedNotification:(NSNotification *)notification {
> if (access) {
> self.contactsArray = [self.addressBook getAllContacts];
> if (self.contactsArray.count != 0) {
> [self performSegueWithIdentifier:@"addEntryrSegue" sender:self];
> } else {
> [self performSegueWithIdentifier:@"noContactsSegue" sender:self];
> }
> }
> }
Thanks in advance. I hope i got this explained well enough.