1

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); 
        }
    }    
}
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
  • 1
    Does it ever show the alert? Can you show your code snipped where you ask for permission? – RyanG Sep 16 '13 at 13:36
  • 1
    Possible Duplicate of http://stackoverflow.com/questions/12596165/is-it-possible-to-reset-the-privacy-settings-in-ios-6 – Puneet Sharma Sep 16 '13 at 13:58
  • @Puneet but on simulator it does not work ( – Matrosov Oleksandr Sep 16 '13 at 14:25
  • Quit simulator and try again. This should not happen. – Puneet Sharma Sep 16 '13 at 14:30
  • Are you very sure you ever saw the alert view on the *simulator*? The iOS 6 [release notes](https://developer.apple.com/library/ios/releasenotes/General/RN-iOSSDK-6_0/index.html) state pretty clearly that the simulator will never show privacy alerts, with location alerts being the only exception. This has also been discussed on [StackOverflow](http://stackoverflow.com/questions/14305070/abaddresbook-permission-in-ios-6-simulator) before. – hagi Sep 17 '13 at 06:29
  • I am sure, it was alert that says about contacts permission. – Matrosov Oleksandr Sep 17 '13 at 11:32
  • 1
    Still, don't expect it to ever appear again, as it's not officially supported. I've never seen it either (using the iOS 6 tools). It may have changed with iOS 7, but I doubt it. On the device, and on the simulator with regard to the location permission, resetting your permission(s) is possible via Settings > General > Reset > Reset Location & Privacy, as indicated in a previous comment's link. – hagi Sep 17 '13 at 11:49
  • @hagi, thank you a lot. I was using XCode 5 as well and iOS 7 maybe this alert was there. if it is connected to this I think I can delete my question. – Matrosov Oleksandr Sep 17 '13 at 11:52
  • You could consider filing a bug report, since either (1) the alert is never supposed to show, or (2) the alert should show again after resetting location/privacy. – hagi Sep 17 '13 at 12:46
  • I have solved it using this [answer][1]. [1]: http://stackoverflow.com/questions/12596165/is-it-possible-to-reset-the-privacy-settings-in-ios-6 – Matrosov Oleksandr Nov 09 '13 at 22:57

1 Answers1

1

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.

Magyar Miklós
  • 4,182
  • 2
  • 24
  • 42
  • yes it is. but The reason why I need alert each time - bugs with it. I am using action sheet and this permission alert, when they appear together here is an bug that I need to reproduce. So if it appeared once how can I fix bug :) you know what I mean. Maybe there is one folder for iOS Simulator that is stored values for permission then I can delete it. – Matrosov Oleksandr Sep 16 '13 at 13:45
  • try to clean build folder, and go to organizer => projects => find your app on the left side , then click on it => delete derived data. – Magyar Miklós Sep 16 '13 at 13:52