We are developed an App which started some interaction with our BLE device by simply presenting a iPhone. Until now we scanForPeripheralsWithServices:options: with background mode. It scanned with a polling frequency of ~1,5secs. But since iOS 16 this polling frequency changed to 10-15secs, which rendered our application virtually useless since the user had to wait up to 15secs until it gets a response.
Related
I am developing an application which is acts bluetooth-central and must scan for peripherals in the foreground as well as in background mode. I have enabled “Uses Bluetooth LE accessory” background mode in Xcode capabilities. After much research, I decided to check if scanning for peripherals, based on ServiceUUIDs, was possible in background mode. After some tests, I was able to scan in background mode. But my problem is that after a few minutes (about 10 min approx or sometimes it’s 25 min) my application automatically stops calling didDiscover peripheral method and terminated automatically. But I need to scan for peripherals in background mode as well and fire some local notifications when some values of particular BLE peripheral will get updated. So for implementing this feature, I need to scan and observe continuously for certain BLE devices even application is in background mode or locked screen by user. Please suggest.
I need to keep scanning for broadcasts from peripherals while the app is in background and when the phone's screen is off. Scanning from background was successful but I can't scan (can't trigger didDiscoverPeripheral) broadcasts when the phone' screen is off.
So far I've implemented beginBackgroundTaskWithExpirationHandler inside applicationDidEnterBackground and that's how I am able to scan in background. So how should I do this?
This is not possible.
When you tick 'Uses Bluetooth LE accessories' and 'Acts as a Bluetooth LE accessory', when iPhone screen light is turned off, core bluetooth framework stops advertising and scanning. It resumes advertising/scanning once the screen light turns back on. That's the maximum possible achievable scenario in iOS.
If you want to take this further, you can use beginBackgroundTaskWithExpirationHandler - https://developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiratio but that works hardly for 3 minutes. Those 3 minutes start as soon as the app goes from foreground to background.
For saving battery, iOS seems to automatically turn off the BLE hardware and it goes back on as soon as the device moves/screen wakes up. Because when screen is off, user isn't using the iPhone anyway.
Edit: Unless a device is connected, like a headphone- Though not advertising, existing connected devices can share data.
I'm working on a proof of concept app. I'm using Xamarin for iOS. The iPhone app runs in the background and watches for particular BTLE devices and speaks using TTS when the signal is at a certain strength. I have TTS working and I can recognize the BTLE devices when the app is in the foreground.
However, I'm having trouble getting either working when the iPhone screen is off. In Android, I'd just use a wake lock, but that appears to not be available in iOS. I tried setting the background modes in the info.plist file for BTLE and sound, but I don't see any processing happen while the unit is suspended. Can anyone point me in the right direction?
This is just a proof of concept, so I'm only looking at the latest iOS version and I'm interested in even hacky answers.
Thanks!
You will need to create at least one background task UIApplication.SharedApplication.BeginBackgroundTask and end it with EndBackgroundTask when you finish transferring your data.
Note that you will have approximately 10 minutes in background. If user switch back to the app the time will be reset.
You might also want to disable application idle timer to prevent the screen to go black when the user doesnt touch it.
Scenario: Backgrounded iOS app monitoring an iBeacon region. The device's WiFi radio was powered down by iOS (30 minutes of inactivity).
When the device enters the region of the the iBeacon and the app wakes to handle the location notification, will the WiFi radio power up and connect to an available remembered WiFi network?
Sending a local notification causes the lock screen to come up. I last tested this in the past (on iOS 6) and as of that OS version, this did cause a WiFi scan to start. Assuming this has not changed in subsequent iOS releases, then yes, this would work as you say.
To be clear, though, this is nothing specific to iBeacons -- this is just about the behavior of iOS when it brings up the lock screen due to a local notification.
I'm developing a Bluetooth Low Energry (BLE) enabled DSLR (digital camera) controller that receives GPS coordinates and allows remote focus/shutter controls.
In the ideal case, I'd not have to take my iPhone out of my pocket.
The BLE device connects as soon as my camera is turned on, and this should launch the app if it's not launched already. When the camera is turned off, BLE disconnects and the app should go into sleep mode (stop updating location and sending data over BLE) (note that app might be in background at this time). When the camera is turned off again (while app is in background/iphone locked), the app should reconnect and start updating location and sending data to the BLE receiver.
It's a lot to ask and might be too good to be true, but is this possible?
(iOS 7+ SDK is OK)
You can operate as a Bluetooth LE central (scanning for peripherals) in the background - Refer to the Core Bluetooth Programming Guide however, while in the background peripheral scanning and detection may not happen as quickly as when the app is in the foreground.
Your app could post a local notification when the peripheral was detected, and the user could respond to this notification to launch your app into the foreground, but you cannot force your app into the foreground without user interaction. You can send information to the camera via BLE even while your app is in the background and you can receive location information while in the background too - refer to the Core Location programming guide.
The disconnection is straight-forward. When you detect a disconnection you can shut down location services to conserve battery power.