For my view controller's viewDidLoad method implementation, it asks the user for address book access. I need to make it so that if the user taps the "Don't allow" button on the alert view window, then we will segue them to another view controller.
My problem is that the segue never happens and shows this output in the console:
Warning: Attempt to present <MediaCaptureVC: 0x156788c0> on <AddFriendsViewController: 0x15670dd0> whose view is not in the window hierarchy!
I have tried several things that have not helped:
Adding a
viewDidAppear
method implementation with my segue code inside of it and calling[self viewDidAppear]
in my viewDidLoad's if statement.Moving my segue code to the very bottom of
viewDidLoad
.
But nothing works. I need a way to trigger the segue even if the view technically is loading because if they deny access to their address book then there is absolutely no reason for them to stay on the view controller.
Here is the beginning of my viewDidLoad
method implementation where I ask for address book access, and then my if statement of if(accessGranted == NO)
contains my segue code of [self performSegueWithIdentifier:@"addFriendsToMediaCaptureSegue" sender:self];
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:YES];
self.currentUser = [PFUser currentUser];
self.tableView.dataSource = self;
self.tableView.delegate = self;
//Asks for access to Address Book.
ABAddressBookRef m_addressbook = ABAddressBookCreateWithOptions(NULL, NULL);
ABAddressBookCopyArrayOfAllPeople(m_addressbook);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
// Write your code here...
// Fetch data from SQLite DB
}
});
ABAddressBookRequestAccessWithCompletion(m_addressbook, ^(bool granted, CFErrorRef error)
{
accessGranted = granted;
NSLog(@"Has access been granted?: %hhd", accessGranted);
if(accessGranted == NO) {
[self performSegueWithIdentifier:@"addFriendsToMediaCaptureSegue" sender:self];
}
NSLog(@"Has there been an error? %@", error);
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);