Search code examples
iosswiftcore-bluetooth

NSBluetoothAlwaysUsageDescription key missing (though present)


While working on an iOS app written in Swift, I am having trouble with the Info.plist. Here is the issue:

The unique Info.plist file contained in the project has an NSBluetoothAlwaysUsageDescription key.

For reference, here is the relevant part of Info.plist:

<key>NSBluetoothPeripheralUsageDescription</key>
<string>The app uses bluetooth to transfer data to a neighbouring device.</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>The app may frequently use bluetooth to transfer data to peers.</string>

But when I run the app on my iPhone, I see this error in the Xcode debugging console:

  2021-06-06 11:20:21.235717+0900 TheApp[5010:1066154] [access] This app has crashed because
  it attempted to access privacy-sensitive data without a usage description.
  The app's Info.plist must contain an NSBluetoothAlwaysUsageDescription key
  with a string value explaining to the user how the app uses this data.

There is already a contradiction at this point that I do not explain.

For some further investigation, I do as follows:

  Product
    -> Archive
      -> Distribute App
        -> Development: Distribute to members fo your team.
          -> Export

There I change the name TheApp.ipa to TheApp.zip and uncompress it. Then inside the Payload folder, on TheApp.app I do:

  Show Package Contents

There I see an Info.plist item which I click to take a look at.

And for some unknown reason the NSBluetoothAlwaysUsageDescription key is indeed missing.

This last point may explain the error message I was getting earlier, but I still don't know why the key has disappeared.

Anyone who can shed light on this issue will be very welcome.


Solution

  • I finally found the solution.

    While looking and trying out various things I discovered a duplicate of Info.plist.

    MyApp copy-Info.plist
    

    This ghost Info.plist contained wrong contents and looking at it, that explained all the weird observations I was making.

    For some reason the building process was using the ghost file instead of using mine. And the actual Info.plist was ignored.