I am coaching a team of 7th and 8th graders working on developing a small app that displays selections from the address book in a large format. You can check out their general project at callmeapp.org. We are stuck on how to prompt the user for permission so we can access the address book. Basically the user prompt is not displaying correctly. FYI, we already know about clearing permissions through Settings>General>Reset>Reset Location & Privacy.
We are using xCode 4.6 and testing on an iPhone MC918LL/A running version 6.1.2.
We started with code from DavidPhilipOster's response in this thread in our appdelegate.m didfinishlaunchingwithoptions method: How do I correctly use ABAddressBookCreateWithOptions method in iOS 6?. We made a few edits to clear errors we were getting.
Right now the app launches to a black screen and sits there for at least 24 seconds at which point the app appears to close revealing the permission prompt underneath. Accepting sends us to the desktop. When we reopen the app it work as if the permission has been cleared. Alternatively if we hit the home button (square one on the phone) while the screen is black it closes to show the permission prompt as above. The permisison window should display after a very short delay and then leave us in the app when the user gives permission.
We stuck in some NSLog points to see what is happening. I have left them in the code in case that helps. It will show points 1, 2, 5 and then wait. After clearing the prompt 3, 7, and 4 enter even though the phone shows the desktop.
Any help or tips would be greatly appreciated.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"Point 1");
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL,NULL);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
NSLog(@"Point 2");
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
NSLog(@"Point 3");
accessGranted = granted;
dispatch_semaphore_signal(sema);
NSLog(@"Point 4");
});
NSLog(@"Point 5");
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
dispatch_release(sema);
} else { // we're on iOS 5 or older
NSLog(@"Point 6");
accessGranted = YES;
}
NSLog(@"Point 7");
return YES;
}