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."
Related
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.
My app keeps listening to voices and analysis them to detect real panic screams. So I want to keep the app running 24/7, but when my app goes in background, the red bar appears on top. Since the recording has to be running for longer period, my app users won't afford to use it anymore. Do you think there is anyway to hide it while recording in background, does Apple has such policy to allow us in such case?
The same question was asked but none is given an answer yet.
I am using AVAudioSession with category AVAudioSessionCategoryPlayAndRecord with options AVAudioSessionCategoryOptionMixWithOthers
Do you think there is anyway to hide it while recording in background
Not "while recording in background". The user needs to know that this is happening.
You can eliminate the red bar — by changing your category and not recording in the background.
But you cannot record in the background without showing the red bar while you are in the background.
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
My app sometimes uses the microphone, but even when I am not using the microphone, the red status bar appears momentarily when leaving my app.
I have set AVAudioSession's category to SoloAmbient. When I record, I set it to PlayAndRecord, and when I am done I set it back to SoloAmbient. But even when the category is SoloAmbient I still see the red status bar.
Even when my app has not accessed the microphone at all I am still getting this red status bar behavior. I do not have the app configured for background audio. Any ideas what might be making the system think that I am recording?
EDIT: After some experimentation, it looks like I can prevent the app from causing the red status bar on launch by delaying creating of the recording AUGraph until I actually start recording.
However, I still see the red status bar after stopping recording. When I stop recording, I stop the AUGraph and dispose of it and change the AVAudioSession category back to SoloAmbient. But I still see the red status bar when I switch away from the app.
After a long long long long long research and hurdles I found out simple solution for this follow as below
In Targets->General->Deployment Info check the HideStatusBar Option
like below!
And in the ViewController (Which one you kept as RootViewController) in viewDidAppear add this line of code...
[[UIApplication sharedApplication] setStatusBarHidden:NO];
Because when you uncheck HideStatusBar Option and your app needs any background process or audio related process then the status bar will become red with enlarged height. If you dont want status bar in entire app then dont add the above line in viewDidAppear and check HideStatusBar Option.
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.