L2CAP channel doesn't work in background

I have an app to communicate with a peripheral via L2CAP channel. Even I already enabled "Uses Bluetooth LE accessories" in "Background Mode", it still stop working when I lock the screen.

Did some search and found these two posts:

I am wondering if there are any solutions or work around about this.

Based on the use case, I prefer to use L2CAP to transfer large data between two devices, so won't consider GATT.

Replies

While it is possible to use L2CAP when the app is in the background, using an L2CAP channel will not prevent your app from suspension, or wake a suspended app like GATT does. LE L2CAP is intended to be used in for higher bandwidth and lower overhead applications where time is a consideration while the app is in the foreground.

That said, you can indeed use L2CAP in the background if your app has the ability (and a legitimate reason) to stay active and unsuspended in the background due to other background supported activities. For example, if the app is designed to stream audio from a BLE device; because your app would have an active AVAudioSession, that will keep the app active in the background, and you can then use L2CAP, as long as the other activity still prevents your app from being suspended.

For solutions in the background with no user facing requirement in the foreground, using GATT is recommended, as it is more resource friendly. While it may be possible to use L2CAP instead by preventing the app from being suspended, keep in mind that such background capabilities ("modes") can only be used if your app has a valid and legitimate reason to do so. Using such modes for the sole purpose of giving the app background runtime may cause your app to be rejected per https://developer.apple.com/app-store/review/guidelines/ section 2.5.4