LaunchAgent (Mac) as peripheral doesn't show a pairing request.

The same code built in a regular Mac app (with UI) does get paired.

The characteristic properties are [.read, .write, .notify, .notifyEncryptionRequired] The characteristic permissions are [.readEncryptionRequired, .writeEncryptionRequired] My service is primary.

In the iOS app (central) I try to read the characteristic, but an error is reported: Error code: 5, Description: Authentication is insufficient.

What context is the agent running in? That is, what do you have set for LimitLoadToSessionType?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I don't set LimitLoadToSessionType. My launch agent is not a GUI app. I'm thinking that may be an issue.

I don't set LimitLoadToSessionType.

OK.

That’s actually good news, because it means that you’re at least running in the right session (the default is Aqua, that is, your agent runs in GUI login sessions).

My launch agent is not a GUI app.

Does it have a GUI app associated with it? If so, try setting the AssociatedBundleIdentifiers property in your launchd property list.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Since my original post, I have a gui launch agent now that acts as a bluetooth peripheral. While it doesn't present a window, it does present a system menu bar item. I have added the AssociatedBundleIdentifiers in my plists used by my SMAppService.agent call. My launch agent advertises a service with a characteristic that uses notifyEncryptionRequired.

After these changes, my iPhone app still gets this error when calling setNotifyValue: Error Domain=CBATTErrorDomain Code=15 "Encryption is insufficient." The error is reported in the didUpdateNotificationStateFor delegate callback.

I chatted with my Core Bluetooth colleague about this, and we’re not entirely sure how the failure you’re seeing can be caused by your execution context. Which isn’t to say that it’s not the case, just that the connection isn’t obvious.

I usually debug problems like this in small steps. For example, in your case:

  1. I would build my agent as an app, with a menu bar and everything.
  2. I’d run that from the Finder (or Xcode) and see if Bluetooth behaves in that case.
  3. I’d then set it to run as a launchd agent, but still with the menu bar.
  4. And re-test Bluetooth. If that works, you know that the launchd agent context isn’t the cause of your issue.
  5. Finally, I’d then switch it to run without a menu bar by setting LSUIElement.
  6. And re-test Bluetooth again.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

All the above steps have been done. Everything works when the characteristic does not have the notifyEncryptionRequired property. This works when run as an app or as a launch agent. When using notifyEncryptionRequired running as an app causes the central to receive the Encryption is insufficient. This also happens when run as a launch agent.

More on how pairing works. I assume that CoreBluetooth would require a pairing for each characteristic as two apps could configure their own characteristic. However that assumption is probably incorrect. If pairing is only done at the peripheral level, then it would make sense that my code receives the Encryption is insufficient error. However, the correct error from the peripheral end would be lnsufficient Authentication (I have seen this error in my code as well) I am no expert on Bluetooth pairing but it would seem that there should be a mechanism to pair on a characteristic basis in order for CoreBluetooth to support different apps providing GATT for the same Mac.

You wrote:

When using notifyEncryptionRequired running as an app causes the central to receive the Encryption is insufficient.

and:

This also happens when run as a launch agent.

So, it being a launchd agent isn’t a factor. That suggest that this is a Bluetooth issue rather than something related to your execution context. I’m gonna invite my Bluetooth colleague [1] to wade in here.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Well, Bluetooth expert colleague. AFAIK he doesn’t actually a Bluetooth transceiver in his head (-:

Hi @pnelson, this is Argun, Quinn's Bluetooth colleague (while I don't have a transceiver in my head, it is not for lack of trying)

I have been discussing your issue with the Bluetooth team, and while we are not dismissing the possibility of a bug, it is possible that the pairing process in different app contexts are behaving differently.

Except we are not able to understand what exactly the conditions are when your app works, and when it doesn't, and when it gets the one error, and when it gets the other. There are also other conditions that might effect the issue, like whether both the Mac and the phone are logged in to the same iCloud account or not (changes pairing details)

To that end, we would like some more info with a sample app, and exact repro steps, and some logs.

So, first please go to https://developer.apple.com/bug-reporting/profiles-and-logs/ and follow the instructions for Bluetooth for macOS and iOS to install a logging profile on each of your devices.

Then, once the logging profile is installed: reproduce the problem, keeping track of the actual time of the actions you take and the result you see.

If you are going to try the GUI, Menu only, Headless options, please keep a detailed log of what test you have conducted at what time, so we can keep track.

Once the problem is reproduced, follow the instructions at the above link to trigger a sysdiagnose

You don't need a separate sysdiagnose for each test, if you are able to run through the whole set within 30 minutes and immediately trigger a sysdiagnose. If it is going to take longer, please trigger separate sysdiagnoses on both ends after each test, and make sure you mark which log file is which.

Also please indicate the iCloud login state of the two devices. And if you can, test with both logged in to the same account and without.

If you can also attach a sample project that we can build in all the configurations that you are testing, we can see and understand what exactly it is you are doing.

Once you have all this ready, please file a Feedback Report at https://feedbackassistant.apple.com/

Once done, please post the Feedback ID here, and make sure to @mention me so I can route the issue right away.


Argun Tekant /  WWDR Engineering / Core Technologies

LaunchAgent (Mac) as peripheral doesn't show a pairing request.
 
 
Q