How to keep Chrome Cast running in background iOS? - ios

I have a simple question when you go to home screen of iPhone and do not quit the application than the chrome Cast device stops playing the video on screen how can I keep playback alive while the application is running in background.

If you have a video app and it is running in a cast device, you would want the following behavior:
if user "explicitly" disconnects a device (through the cast menu), then receiver should look at the connected devices and see if there is any "other" connected device. If there is none, it should stop the application on the cast device. If, however, it finds another connected device, it should not stop the app.
If user doesn't explicitly disconnect but device gets disconnected since the app goes into background, or phone goes out of wifi range, or it battery dies, or ..., then receiver should not stop the app and should let it run, even if there is no other connected sender.
If you follow these two in the design of your app and your receiver, then you shouldn't have any issue when your phone goes to sleep or your app goes to background. Do you still see an issue given the above?

Related

Launch app in background when BLE device is in range

I'm making an iOS app to support a Bluetooth LE device. First time the app launches, we pair, but after that I want to communicate with the device whenever it is in range. Using background modes, this works fine for when the app is launched and goes into background and the screen is turned off. But, when the phone is rebooted, the app needs to be relaunched before it will be able to detect the device.
Is there any way to have the app launch in the background whenever the BLE device that it is paired to comes nearby?
In case of user forcibly kills the app by double clicking on home button and swipe out, it will not be relaunched until the user launches it again.
Coming to your case when Device is rebooted - Yes, you can configure State Preservation and Restoration to relaunch the app when user has not killed it forcibly before rebooting.
( Note: If the device requires a passcode to unlock, apps will not be relaunched until the device is unlocked for the first time after a restart )
Also, it is important to keep in mind that the app will be relaunched and restored if and only if it is pending on a specific Bluetooth event or action (like scanning, connecting, or a subscribed notification characteristic), and this event has occurred.
For more info:
Conditions Under Which Bluetooth State Restoration Will Relaunch An App

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.

Bluetooth icon stays white?

I am working on an iOS app which uses Core Bluetooth. When the app gets SIGKILL-ed, the Bluetooth icon on one device stays white, even though it isn't connected to anything. When I next run the app, that device has problems connecting to the other device.
How do I "refresh" the connections? Or is there a way to cancel connections before the SIGKILL?
(The devices have to stay connected even when the app is in the background)
As an experiment you can try to retrieve the connected devices with the retrieveConnectedPeripherals method. If the device you are trying to connect is in the connected list, then it may be possible to start using it again.
Also, try to forcefully disconnect the other device by removing the battery or turning it off. If the connection stays there, then this is definitely a bug.
This is most probably an iOS bug or some optimization that is implemented only for handling connections between i* devices. I don't know of others having this issue, neither did I stumbled upon it but in these cases it is best to report it to Apple at the same time with as much info as you can provide (https://bugreport.apple.com/) You should try with newer iOS versions as well to see if it still exists.

UIApplicationExitsOnSuspend and screen refresh

I have an app that has the UIApplicationExitsOnSuspend info list property set to TRUE.
And now I am noticing a curious issue.
I start up the app and let it run on my phone and do not touch my phone. Eventually the phone screen goes dark and the phone goes into standby mode. When I wake the phone up, what I see is a screenshot of the last screen displayed on the app. (This seems according to spec, since the Apple documentation says that in the process of moving an app to the background, ios takes a picture of the app and uses that for transitions when the app comes back to life). If I double click on the home button to see running apps, I do not see an instance of the app running. (again, working as intended since UIApplicationExitsOnSuspend is set to true).
My question is, how do I make sure that when the phone wakes up, it comes back to the default home screen and not the picture of the app ? Clearly the app is not running on waking up, so there is nothing I can do from within the app that will refresh the screen. I could try to exit when the app is going to background, but then apple guidelines say, never exit programatically!!.
Any ideas ?
You misunderstand what is happening. If you enable UIApplicationExitsOnSuspend, this means your app will terminate when normally the app would go to the background. If you run your app then let the phone sit idle until the screen goes dark, your app is still in the foreground so it is not terminated. When a device goes into standby mode, the current app is still the current app. When you wake the device, you are not looking at snapshot of your app, you are looking at your running app. Double-tapping the Home button at this point doesn't show your app because your app is the currently running app.
Your app will be terminated if you return to the home screen or switch to another app. But it will not terminate just because the device went into standby mode.
If you want your app to return to its main screen when the device is woken up, then you need to put code in the UIApplicationDelegate applicationDidBecomeActive: method to reset your user interface.

How to programmatically wake an external screen attached to an iPad

I'm developing a standalone kiosk that is composed of an iPad 2, and an external screen. I have the two connected by cable, and the iPad is locked in a special case to prevent it from disappearing. This case makes the access to the connector impossible.
The problem I have is that when the iPad wakes from sleep (user interaction) the screen often doesn't wake up. Once the screen awake however, there is never a problem of it going to sleep by itself (this rules out a physical connection problem). I manage to wake up screen after several tries of switching on/off the monitor or letting the ipad fall a sleep and then waking it up.
My guess is that the iPad fails to send the signal while the monitor is scanning for it. However, after several tries I get them both to do their things at the right time, and that is when it all starts to work.
Hence the question. Can I programmatically make the ipad scan (send signal to) the external monitor? Ideally I would do it from the app I'm developing, but a standalone app could solve a trick too.
I've looked through the UIScreen Class reference and googled quite a bit, but so far to no avail.

Resources