简体   繁体   中英

prevent iOS app from sleep but retain lock screen and screen dimming

My app communicates with an external accessory, however seems there is a bug that when the ios device comes back from sleep sometimes the EAAccessoryManager list is empty. The app is already in the field and I need a fix as currently the users have to turn the external accessory off and on for it to work again.

I am thinking of preventing the iOS device from going to sleep. However I do not want the LCD screen to be on always as that will drain the battery. I also want the lock screen to activate for security purposes. What are my options?

Btw the EAAccessoryManager list is usually empty after the device awakes and the user has to enter an unlock code. Seems if I use the fingerprint it is fine, so believe it is a bug in iOS 10.3.3? Any one else encounter this?

I'm pretty sure its not possible to prevent the device from going to sleep IF it is already showing the lock screen. Since the lock screen is a system thing which you have absolutely no control of.

However, you might be able to fix your issue by implementing background modes for your app.

Apple allows apps who are using external accessories to keep running in the background, which means your app should be able to stay connected to your accessory performing whatever it is it should do.

By the way, i'm not sure about the EAAccessoryManager, but when I implemented something similar using BLE I noticed that the scan DOES NOT SHOW the accessory as discoverable if its already connected to it. Are you sure its not already connected which is why it's showing an empty list?

Something else i noticed is that by saving its UUID i could simply ask my device to connect to it regardless of it is advertising or not. EVEN if the device was turned off. This would result in when the device got turned on my device would automatically connect to it (without me sending the "connect" message)

Thanks staight after I posted the question I found that setting UIBackgroundModes to external-accessory did the trick and resolved my problem. I'm not sure whether this is required for all external accessories but in case someone has the same issue.

It must be noted that my app doesn't actually need to use the external device while in the background but at least this resolves the issue and also screen dim, screen locks as expected.

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