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:
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:
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);