Reputation: 6707
It's something that I didn't know till an hour ago or so, but if your application tries to access Contacts (previously, Address Book) data through the ABAddressBook
Class, the user will be prompted for confirmation just as you will be prompted for confirmation when an iOS application tries to access Contacts data. Then the Security & Privacy Preferences Pane will be updated, and you will see your application listed under the Privacy list.
So if you try to access Contacts data with the application blocked, you will get an error with Xcode stating like "Address book access is denied for executable at path..." You can check the privacy status with ABAddressBookGetAuthorizationStatus()
in iOS. How do you find out if your application has privacy permission in OS X?
Additionally, if you have the answer, I wonder where Mac OS stores the list of applications under the Privacy tab? I've checked User's Preferences folder. But I don't see any file with it.
Thank you for your help.
// Edit 1 //
The following is an error output shown when the application attempts to access ABAddressBook with ABAddressBook *addressBook = [ABAddressBook sharedAddressBook];
:
2013-08-14 21:47:59.796 AppName[5374:1803] Address book access is denied for executable at path: /Users/Jim/Library/Developer/Xcode/DerivedData/AppName-eymlymijdmbqaldaqcaecgdyroxa/Build/Products/Debug/AppName.app/Contents/MacOS/AppName
(
0 AddressBook 0x00007fff8a1232fc __ABIsAccessGranted_block_invoke_0 + 36
1 libdispatch.dylib 0x00007fff93f5b0b6 _dispatch_client_callout + 8
2 libdispatch.dylib 0x00007fff93f5b041 dispatch_once_f + 50
3 AddressBook 0x00007fff8a123258 ABIsAccessGranted + 40
4 AddressBook 0x00007fff8a12319e +[ABAddressBook sharedAddressBook] + 12
5 AppName 0x00000001000180e7 -[AppDelegate extractWorkAddresses] + 55
6 AppName 0x0000000100011a68 -[AppDelegate extractWork1Address:] + 72
7 AppKit 0x00007fff8c9f6989 -[NSApplication sendAction:to:from:] + 342
8 AppKit 0x00007fff8cb2c37c -[NSMenuItem _corePerformAction] + 406
9 AppKit 0x00007fff8cb2c06a -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 133
10 AppKit 0x00007fff8c81928f -[NSMenu _internalPerformActionForItemAtIndex:] + 36
11 AppKit 0x00007fff8c819117 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 135
12 AppKit 0x00007fff8cb25175 NSSLMMenuEventHandler + 342
13 HIToolbox 0x00007fff8a84cd1a _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1206
14 HIToolbox 0x00007fff8a84c1e9 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 410
15 HIToolbox 0x00007fff8a861fc9 SendEventToEventTarget + 40
16 HIToolbox 0x00007fff8a898ca9 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 443
17 HIToolbox 0x00007fff8a83da21 SendMenuCommandWithContextAndModifiers + 59
18 HIToolbox 0x00007fff8a83d9d3 SendMenuItemSelectedEvent + 254
19 HIToolbox 0x00007fff8a83d85f _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 94
20 HIToolbox 0x00007fff8a8198bb _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 605
21 HIToolbox 0x00007fff8a818ec8 _HandleMenuSelection2 + 565
22 AppKit 0x00007fff8c9e48f6 _NSHandleCarbonMenuEvent + 245
23 AppKit 0x00007fff8c906acf _DPSNextEvent + 2073
24 AppKit 0x00007fff8c905e22 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
25 AppKit 0x00007fff8c8fd1d3 -[NSApplication run] + 517
26 AppKit 0x00007fff8c8a1c06 NSApplicationMain + 869
27 AppName 0x0000000100002092 main + 34
28 AppName 0x0000000100002064 start + 52
)
Upvotes: 1
Views: 956
Reputation: 119031
If the user grants access, your application can access ABAddressBook
as usual. If the user denies access, the addressBook
and sharedAddressBook
methods of ABAddressBook
return nil.
I don't think there is a way to avoid that exception (which doesn't match what the docs say should happen). So, you can add that section of code where you try to get the sharedAddressBook
into a try catch
block and avoid the app dying if the exception is thrown.
Upvotes: 2