__CRASHING_DUE_TO_PRIVACY_VIOLATION__

2020-07-02 11:46发布

问题:

In Crashlytics, I can see iOS 10 users are getting this crash frequently. However, when I test in Simulator using iPhone 7/10.2, I'm unable to reproduce the crash. In my plist, I already have strings for

NSCalendarsUsageDescription, NSMicrophoneUsageDescription, and NSPhotoLibraryUsageDescription.

Here is the stacktrace from Crashlytics:

Crashed: com.apple.root.default-qos
0  libsystem_kernel.dylib         0x183765d74 __abort_with_payload + 8
1  libsystem_kernel.dylib         0x18376249c <redacted> + 100
2  libsystem_kernel.dylib         0x1837624c8 abort_with_payload + 10
3  TCC                            0x1869d6328 __TCCAccessRequest_block_invoke_2.80 + 258
4  TCC                            0x1869d6224 __CRASHING_DUE_TO_PRIVACY_VIOLATION__ + 702
5  TCC                            0x1869d9330 __tccd_send_block_invoke + 348
6  libxpc.dylib                   0x18386afcc _xpc_connection_reply_callout + 80
7  libxpc.dylib                   0x18386af3c _xpc_connection_call_reply + 40
8  libdispatch.dylib              0x1836221bc _dispatch_client_callout + 16
9  libdispatch.dylib              0x183630a4c _dispatch_queue_override_invoke + 732
10 libdispatch.dylib              0x18363234c _dispatch_root_queue_drain + 572
11 libdispatch.dylib              0x1836320ac _dispatch_worker_thread3 + 124
12 libsystem_pthread.dylib        0x18382b2a0 _pthread_wqthread + 1288
13 libsystem_pthread.dylib        0x18382ad8c start_wqthread + 4

Any clue how to reproduce or fix this? I do allow user to access contacts, but I am not prompted for any permission when I test that feature in simulator. However, when the user accesses the camera from my app, the simulator does prompt me for a permission. That makes me think that a string is not needed for accessing contacts.

回答1:

If you're seeing these crashes on iPhone X and you use Touch ID/Face ID, the reason might be a lack of NSFaceIDUsageDescription key in your Info.plist. The key was added in iOS 11 and looks like it might have become mandatory after iOS 11.3, given that I see a spike of crashes on iPhone X after iOS 11.3 was released. It's vaguely documented by Apple here:

NSFaceIDUsageDescription (String - iOS). This key lets you describe the reason your app uses Face ID.

Important: To protect user privacy, an iOS app that links on or after iOS 11 and that would access Face ID if the hardware supports it, must statically declare the intent to do so. Include the NSFaceIDUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access Face ID without a corresponding purpose string, your app may exit.

This key is supported in iOS 11 and later.

Interestingly enough, I wasn't able to reproduce the crash on iOS 11.3 on my development iPhone X, maybe it behaves differently in debug or TestFlight builds. Still worth adding the key when you use Face ID in your app, if we believe Apple's documentation.



回答2:

I had to add a string for NSCameraUsageDescription in the plist because user is allowed to take photos.



回答3:

Let's understand two things.

In the plist file there so many privacy keys for example camera usage, contact usage location usage, face id usage, etc... if you miss any of the keys and try to use those features you will get a crash, so use keys and description for avoding crash.

2nd thing is, especially for NSPhotoLibraryUsageDescription, if you were using this key from above iOS 6 and below iOS 11.3 then you will not get any crash, but after iOS 11.3 and later you need to add one more key which is NSPhotoLibraryAddUsageDescription.

At the same time, you may use both keys if your app is iOS 8 or 9 or above to latest iOS 11.3 and higher.

Reference for all the keys



回答4:

The __CRASHING_DUE_TO_PRIVACY_VIOLATION__ crash happens whenever there is a mandatory permission string missing on the app's plist. Permissions level are changed by Apple with new iOS versions sometimes. So code that was working will start breaking with iOS updates that have new requirements for the plists.

You should evaluate what of the permissions listed on all the answers here may affect you (NSFaceIDUsageDescription, NSCameraUsageDescription, NSPhotoLibraryAddUsageDescription, others?) as you may not be using any of those features on your app.

In my case, we support a Bluetooth BLE device and from iOS13 there was a new mandatory permission needed: NSBluetoothAlwaysUsageDescription so I added to my plist:

<key>NSBluetoothAlwaysUsageDescription</key>
    <string>We use Bluetooth to connect to your ... while the app is in the background</string>

And that fixed it.



回答5:

I had the same problem with a iphone X running iOS 14. Solved the problem adding NSPhotoLibraryAddUsageDescription to my info.plist file.

acording to this forum : https://forums.developer.apple.com/thread/100732



回答6:

You must need to grant the permission from user to access the AddressBook.

  #import <AddressBookUI/AddressBookUI.h>

  // Request authorization to Address Book
  ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

  if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
      if (granted) {
          // First time access has been granted, add the contact
          [self _addContactToAddressBook];
      } else {
          // User denied access
          // Display an alert telling user the contact could not be added
      }
    });
  }
  else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access, add the contact
    [self _addContactToAddressBook];
  }
  else {
    // The user has previously denied access
    // Send an alert telling user to change privacy setting in settings app
  }

There is update on iOS 9.0 and above:

From Apple website :

Important The Address Book UI framework is deprecated in iOS 9. Use the APIs defined in the ContactsUI framework instead. To learn more, see ContactsUI.



回答7:

Case 1

I got the same crash report when attempting to read files using a UIDocumentPickerViewController without first calling startAccessingSecurityScopedResource() on the returned URL.

Case 2

Here's another possible (corner) case:

If you use EKEventEditViewController to add events to the user's calendar, the NSCalendarsUsageDescription key in your info.plist might not be enough!

If the user attempts to add invitees to the event, the NSContactsUsageDescription key is also required. Otherwise, when the user attempts to search through their contacts, the privacy violation occurs and the app crashes.