Question

My app uses Address Book framework. To show all contacts in iOS 6 or higher I have to set permission for it.

At first time when I was running my app on the simulator I saw this alert below, but when I try to show it again I don't see the alert one more time.

enter image description here

I have reseted content and settings but it has not helped me. So when I rerun app it all time shows contacts, but at first the app has to show alert when I reseted simulator. Anybody faced with this issue?

Code below:

- (void)getPersonOutOfAddressBook
{

    if (self.tableData) {
        [self.tableData removeAllObjects];
    }

    ABAddressBookRef addressBook = ABAddressBookCreate();    

    __block BOOL accessGranted = NO;
    if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
        dispatch_semaphore_t sema = dispatch_semaphore_create(0);
        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
            accessGranted = granted;
            dispatch_semaphore_signal(sema);
        });
        dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
        dispatch_release(sema);
    }
    else
    {
        // we're on iOS 5 or older
        accessGranted = YES;
    }

    if (accessGranted)
    {        
        if (addressBook != nil)
        {
            NSLog(@"Succesful.");

            NSArray *allContacts = (__bridge_transfer NSArray
                                    *)ABAddressBookCopyArrayOfAllPeople(addressBook);
            NSUInteger i = 0;
            for (i = 0; i < [allContacts count]; i++)
            {
                Contact *contact = [[Contact alloc] init];

                ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i];
                NSString *firstName = (__bridge_transfer NSString
                                       *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty);
                NSString *lastName =  (__bridge_transfer NSString
                                       *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty);
                NSString *fullName = [NSString stringWithFormat:@"%@ %@",
                                      firstName, lastName];

                NSData  *imgData = (__bridge NSData *)ABPersonCopyImageData(contactPerson);

                contact.firstName = firstName;
                contact.lastName = lastName;
                contact.fullName = fullName;
                contact.image = [UIImage imageWithData:imgData];

                [self.tableData addObject:contact];
            }

            CFRelease(addressBook); 
        }
    }    
}
Was it helpful?

Solution

My experience is: when you install an app to your device it will ask you to allow or not something. If you delete it and install it again it won't ask you again. For example an app want to know you enable or disable push messages. If you tell: yes I enable, and then you remove the app from the device, and after you download again, and install it won't ask you again. It s just automaticly appears in your settings. Address book can work the same , but I'm not sure. GPS is not the same, applications ask you evertime to enable location.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top