Pregunta

I have a view controller in my app that needs to access the user's address book to get their contacts.

When the user first lands on the view controller, this is the UIAlertView window that pops up:

enter image description here

I would like to be able to customize the text that is in the UIAlertView window. I know this is possible because when using an app like Secret, this is what their UIAlertView window looks like when they want access to your address book:

enter image description here

So, how can I customize the UIAlertView window content when programmatically asking for access to the address book contacts?

Here is the code that I am using so far:

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

//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);
        NSLog(@"Has there been an error? %@", error);


        dispatch_semaphore_signal(sema);
    });
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
else { // we're on iOS 5 or older
    accessGranted = YES;

    NSLog(@"Address book access has been granted.");
}

if (accessGranted) {


    NSArray *allContacts = (__bridge_transfer NSArray
                            *)ABAddressBookCopyArrayOfAllPeople(m_addressbook);
¿Fue útil?

Solución

You can set the text explaining why you need to access contacts in the application's property list by adding NSContactsUsageDescription key with a string value specifying your explanation.

Otros consejos

In Xcode, select yourAppName-info.plist, Add an item to Information property list, select Privacy - Contacts Usage Description and set the description string. If you test on simulator, go to settings of simulator / general / Reset / Reset Location and Privacy now you'll have the message.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top