简体   繁体   中英

How to send battery updates to LE accessory from app in background when iPhone operate in peripheral mode?

I'm developing a BLE enabled App. In my App iPhone operate in peripheral mode with Bluetooth accessories. Everything works fine until I go to background Mode Because my Phone is working as peripheral so It also update accessory with battery level it doesn't work in background because app will only wakeup once accessory will send request because its already subscribe for the update I somehow have to wakeup my app in background mode and send update let's say every x minutes . I have already enable Bluetooth LE accessory background mode.

Apparently enabling background mode only gives the 'right' to run in the background whenever there is an event triggered.

One of the method is what you already did by 'polling' from the accessories periodically by sending request to wake up the app and execute the task.

Another way is to use background refresh. The only downside of background refresh is the event will not occur at specific period. It was mentioned at about 10-15mins typically or it might tag along with other app background wake up. If the update is not very frequent or crucial, this method would probably better for your case.

You can keep your app running in background by setting the "required background modes" option in your plist. Select "App communicate with accessory".

Please see the attached image for reference 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM