Xamarin - iOS backgrounding with BT low Energy and TTS - ios

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.

Related

Chirp Audio QR Fails to receive audio signals on ipad after resuming from background

Chirp audio QR frame work is not receiving data after resuming from background (This issue is only happening on iPAD devices iOS11+)
If the app is in foreground then framework works without having any issues, but if app goes background and then resuming this happens.
Joe from Chirp here. Are you stopping the SDK when moving to the background, and starting again in the foreground?
See our example project at https://github.com/chirp/chirp-ios-examples/blob/master/Swift/Messenger/ChirpMessenger/AppDelegate.swift for an example of this.
I have just tested this on an iPad running iOS 11.4.1 and data is still received when foregrounded.
I you want the app to receive/record audio when it goes into the background state, then Background Audio must be set in the Capabilities plist. Otherwise the OS will remove the microphone connection from your app's process (to allow the new foreground app to possibly use it).

Core Bluetooth scan for peripherals while the phone's screen is off

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.

Total screen unlock time calculation in iOS

For my current project, I need to calculate the total time while an iOS device is unlocked i.e. the user is working on his device. I am aware of the Darwin Notifications as available in CFNotificationCenter as specified in this Stackoverflow question. I have tested this code on my iPhone 5C. It is woking fine for foreground mode. But I am not able to receive those notification when the application is in background mode. Is it possible to receive those notification in background mode? Or is there any other way to calculate total unlocked time for a device from my app even when the application is in background mode?
As explained here. Background mode can only be used for specific purposes. If your App is not using background mode for any of those purposes (which it isn't), it will not work.
In short, it could only work on a jailbroken device.

App Interruption - Siri Fails To Hear Human Voice

In my team's iOS app we have a bug when Siri is invoked while our app is running. Siri pops up and the waveform is shown very briefly and appears not to detect one's voice as the waveform remains very flat. Quickly thereafter it begins to list the things you can ask Siri.
We are using Xcode 6.3, tested on an iPad Mini with iOS 8.3 as well as an iPhone 5 with iOS 8.3.
The app never uses the microphone or queries any of the device audio inputs so I can't see this problem attributed to our app using the microphone directly. It does play looping ambient music and has sound effects.
Is there anything specific we should be calling an an interruption to ensure that Siri will work properly? Has anyone experienced similar issues?
This is most likely not related to your app. The iOS SDK doesn't provide a Siri API that could lead to this kind of events.
You may try to pause any ambient music/sounds effects whenever the app goes in background. (in AppDelegate.m)

Launch app from background service

I've developed Android app which has a background service in the sleep mode. This service works with accelerometer data and can launch the app from the sleep mode over the lock screen.
Is it possible to make the same on iOS?
I mean:
Create a service which can work in background with accelerometer data.
Service can launch the app when the phone is in the sleep mode over lock screen. (without unlocking)
If I'm not mistaken it must be possible on iOS7, isn't it?
Thanks!
Yes – Apple publicly stated background processing at WWDC keynote and it can be done to a degree on iOS6
No – Apple will 'probably' never allow an app to be opened without the user instigating it and certainly not over the lock screen.
You could use Push / Local Notifications which do appear on the lock screen to try and entice a user at a specific time to launch the app but no guarantees.

Resources