Due to requirements with our content providers our app needs to be able to disable the ability to Airplay Mirror our player while in Picture in Picture with the application in the background.
While the application is in the foreground we observe the UIScreenDidConnectNotification, and utilize that in order to present another screen, but when the application has gone into the background the observer is not notified until the application has come back into the foreground. This allows our DRM video content to be mirrored to an AppleTV while Picture in Picture is active.
We have also tried to observe the 'isExternalPlaybackActive' property of the AVPlayer instance, but even with using a sample project utilizing a AVPlayerViewController, we were unable to observe any changes to that value. With a timer we also verified that even with the app in foreground, and the AVPlayer instance in full screen, that when mirroring content that value does not change. The only time Key Value Observing shows that value change is when it is initially set as well.
We have also attempted to setup a timer that using NSOperation will continue in the background while Picture in Picture is active. With Picture in Picture active and the application in the background it was observed that there was no change to the UIScreen.screens.count remaining at the same value of 1. It was also observed that the isExternalPlaybackActive property for the AVPlayer instance remained 'false'.
Another attempt we have made is to set the AVPlayer's 'usesExternalPlaybackWhileExternalScreenIsActive' and 'allowsExternalPlayback', but this also failed at preventing the player from displaying through Airplay Mirroring.
With those attempts we have exhausted the resources from the documentation, and would like to find a solution that still allows us to enable Picture in Picture with the app in background.
Related
I have a simple app which streams live video from a server and me using AVPlayer. Now my concern is, after playing the video for 20-30 min the app automatically goes into background mode, even though there is no crash or exception.
The behaviour is - app running in foreground mode and video playing and then suddenly the app goes into background mode.
Since I have registered for "UIApplicationDidEnterBackgroundNotification" and hence come to know app goes to background mode. I'm not sure how the BackgroundNotification is getting triggered automatically even user does not press home-button at all.
Is there any delegate method or callback which makes the app go into background mode?
thanks
That is not the background mode, that is screen lock. You can prevent the device from locking screen using this:
UIApplication.shared.isIdleTimerDisabled = true
Don't forget to set it to false again once you reach the end of the video or if user leaves the player view.
I am writing an iOS app that keeps and displays the state of a system. It basically shows a light whose color represents state:
green/yellow/red light <==> OK/warning/danger
I'd prefer to show accurate state even when the app is backgrounded, and its snapshot is viewed thru the iOS multitask viewer (the view that looks like a rolodex, which you get after double-clicking the home button). I REALLY don't want to show a snapshot which displays an inaccurate state.
So my question is: can you change the view (or perhaps the app snapshot) while the app is in the background, so that when it's viewed in the multitask view it shows an accurate state.
I've seen that this is not recommended by Apple: from App Programming Guide for iOS
Avoid updating your windows and views. Because your app’s windows and views are not visible when your app is in the background, you should avoid updating them. The exception is in cases where you need to update the contents of a window prior to having a snapshot of your app taken.
However, Apple's music app does just this...if you start playing a playlist, then put the music app into the background, the cover art gets updated as the music app works thru the playlist. So this functionality must be possible somehow.
The best answer I can come up with after a bunch of searching is to alter my app's view to the splash image prior to entering background operation. This would ensure that inaccurate state isn't displayed, but also prevents showing accurate state.
You can change the snapshot view immediately before the snapshot is taken (A banking app, for example might want to obscure personal information), but you cannot continue to update the snapshot from the background once your app is suspended. You may want to adopt this approach in order to avoid displaying an inaccurate state; show nothing rather than stale data.
You might also want to consider some other options, such as a "today" widget that contains the updated status or posting local notifications when there is a significant change in status (such as entering the "red" state).
When my app is sent into the background, a red status bar flashes briefly. I can live with that. The problem is, if the user then changes the route (eg., plugs or unplugs headphones), the red status bar comes on and stays on (until the app is killed or foregrounded).
My app uses audio session category AVAudioSessionCategoryPlayAndRecord, but not when backgrounded. I change the category to playback and then deactivate the audio session when the app goes into the background, but have not been able to suppress the red flash nor the bigger problem with route changes.
Looks like changing the category isn't sufficient -- if the session was created with inputEnabled true, then you're stuck with the status warnings. You'll have to release the session completely. See this question for discussion with final answer "...the only way is to actually release audioController."
I'm currently working on an app which reminds the user, when he gets to an certain location. I want this app working in background as well and searched for solutions.
In the AppStore i found the App called Sleep Cycle, which tracks your activities during your sleep. When you set the alarm, and running the App in the Background you get this screen red bar on the top of the Display of your iPhone.
http://i.stack.imgur.com/uEejp.jpg
Does anybody know what kind of Backgroundmode this is, and how i can transfer it to my app?
Thanks
To have such a red bar I use audio background mode and also I record sound in background. Since Sleep Cycle asks user to allow access to microphone I believe it also records audio in background
I am creating an alarm clock app that requires some user action within the app in order to turn the alarm off. Below is a picture of what another app, Sleep Cycle, does when you turn an alarm on and press the home screen (i.e. background the app).
Here is an image link (I can't post an image yet, no rep despite my many attempts to answer people's questions today) for the effect I want to re-create.
Those that have used iPhone's Personal Hotspot and connected a device will notice that it is the same effect, where a notification appears at the top of the UI - pushing everything down by around 20-40 points. This is highly desirable to an alarm clock app as it encourages the user to keep the app in the foreground so that the app can easily be entered when waking up (instead of relying on the 30 second sound window allowed by local notifications)
Does anyone have any ideas on how to implement this functionality. I assume that it must go somewhere in the:
- (void)applicationDidEnterBackground:(UIApplication *)application
tag within the AppDelegate, but I'm not sure what exactly I need to be reading up on. So if anyone has a link to some relevant Developer Docs that would also be extremely helpful.
Many thanks for your help,
Ryan
There are a handful of built in 'background modes' that change the status bar's appearance depending on what functionality an app provides whilst it's in the background. The one you've identified (a red status bar) is triggered when an app records audio whilst in the background. I presume Sleep Cycle must be acting as though it records audio just for this purpose. Other background modes include VoIP (which I think uses a blue status bar). Check out Apple's documentation on supporting these various background modes
In your case, you'd want to add audio to the UIBackgroundModes property in your Info.plist file.
But note that it wouldn't be unreasonable for Apple to reject an app during review if it pretends to perform one of these background tasks but doesn't. For example, there have been apps in the past that tried playing a silent audio clip continuously in order to stay awake in the background - needless to say Apple got wise to this and the app in question had to change its behaviour.