Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120127

Bluetooth advertising in Qt UI app behaves as if it was in the background.

    XMLWordPrintable

Details

    • macOS

    Description

      We have a Qt app that is advertising iBeacons on macOS. We use macOS's CoreBluetooth API to do this (we tried CoreLocation instead, and found the same patterns). Sometimes on some macs no iBeacon advertisement can be observed even though the app is running. This is believed to be because other processes are advertising something else (e.g. "sharingd", AirDrop, Handoff etc.) at the same time. 

      During the summer of 2023 I had an e-mail correspondence with Apple support about this issue. Then I was told that: "for advertising to be recognized, apps need to be in the foreground.", I also interpreted this as: apps in the foreground will be able to advertise (On iOS this statement is clearly true).

      I will share two examples of unexpected behaviour that I discovered during this debugging. I have one app "CmdApp" which is a command line app that advertises an iBeacon, it is built with Xcode 14.3. I have a second app "UIApp" which is the same functional code, but with a minimal UI, also built with Xcode 14.3. I also have a third app "QtApp" which again uses the same functional code but is built using Qt.

       

      Experiment 1 - 2 Command line apps:
      -----------------------
      I tried having two instances of CmdApp send iBeacons simultaneously.

      Steps.
          1. Start App1 which advertises iBeacon1. Obs: iBeacon1 is advertised.
          2. Start App2 which advertises iBeacon2. Obs: still only iBeacon1 is advertised.
          3. Kill App1, now only App2 is running. Obs: still only iBeacon1 is advertised.

      See the attached image "2CmdApps.png" for a diagram showing this. 

       

      Experiment 2 - 2 UI apps:
      -----------------------
      Do the same as Experiment 1, but with UI apps.
      Steps:
          1. Start App1 which advertises iBeacon1. Obs: iBeacon1 is advertised.
          2. Start App2 which advertises iBeacon2. Obs: still only iBeacon1 is advertised.
          3. Kill App1, now only App2 is running. Obs: iBeacon2 is advertised.

      This is different behaviour from the command line apps, when the first app is killed, the second starts immediately to advertise its iBeacons. See the attached image "2UIApps.png" for a diagram showing the experiment.

       

      The thing is that QtApp behaves exactly like CmdApp. Why is this? QtApp does have a UI and should be either in the foreground or in the background, but it behaves as if it is in the background. We have strong evidence that if QtApp behaved like an Xcode UI app (like UIApp) our problem would be solved.

       

      I have attached:

      • Timing diagrams, showing the two experiments.
      • 2 instances of the CmdLineApp, one that advertises UUID=111...1 and one that advertises UUID=222...2.
      • 2 instances of UIApp, one advertising UUID=111...1 and one advertising UUID=222...2.
      • 2 instances of QtApp, one advertising UUID=111...1 and one advertising UUID=222...2. 

      Attachments

        1. 2CmdApps.png
          2CmdApps.png
          17 kB
        2. 2UIApps.png
          2UIApps.png
          17 kB
        3. CmdLineAppUUID1.zip
          36 kB
        4. CmdLineAppUUID2.zip
          36 kB
        5. QtAppUUID1.zip
          8 kB
        6. QtAppUUID2.zip
          8 kB
        7. UIAppUUID1.zip
          46 kB
        8. UIAppUUID2.zip
          45 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ablasche Alex Blasche
            steinarc Steinar Christensen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes