app goes into background mode after running video for sometime - ios

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.

Related

Disable Mirroring of AVPictureInPictureController while app in Background

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.

Sleep Cycle - What kind of Backgroundmode is this?

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

IOS App and Background

I have a music signal processor app I want to publish and it needs to run in the back ground. I used to Info-plist to do so with UIBackgroundModes. It runs on IOS7 or less, and the problem I am having is once the phone locks and the app goes into the background I can't get it to come out of the background and its keeps running with the red banner at the top. Some of this I have learned as I go, but I have noticed some run on a timer, but I want mine, since its a music processor to keep going until the phone either unlocks or whatever interrupted it stops.
The app is basically a stomp box used with iRig. If that helps.
Thanks
Can you clarify about what you mean when the phone locks, the app goes into the background and yo can't get it to come out of the background? Are you saying like the app is playing music while the app is locked?

No sound after waking up

We've been using the AIR sound API, building for iOS, with no problems till now, the problem is that the sound works until iPad goes to sleep and there's no sound from our app when iPad is woken back up.
Note: we have the app set to exit on suspend, and we don't have this problem when user suspends -- i.e, hits the button and goes back to desktop.
We only have it when iPad goes to sleep (screen goes dark but app is still running). As far as I can tell our app is not receiving any events from iOS when the iPad goes to sleep or wakes back up. Once this has all happened and the game has no sound, but exiting and restarting makes it work again.
We are getting an activate event from the native application object when iPad is woken up, I'm also checking (just because it sounds useful) the value of SoundMixer.areSoundsInaccessible, but that's way off base. I do get a soundchannel object back when I play a sound while the problem is in effect, I just can't hear it.
We were having a similar problem with audio not playing (roughly half the time the device had been asleep), and fixed it with this:
// AudioPlaybackMode.MEDIA is the default value
SoundMixer.audioPlaybackMode = AudioPlaybackMode.AMBIENT;
Once that was done, audio came back immediately after the app woke up.
Note that AMBIENT's behaviour depends on whether the microphone is being used.

ios background app is slow to respond from MPNowPlayingInfoCenter

I created a music app that is wired up to MPNowPlayingInfoCenter. I have a bunch of methods that do various things (next, pause, etc). However, when I hit the next button in MPNowPlayingInfoCenter, the app responds immediately and calls the method instantly when the app is active. However, when the app is playing the background and I hit next from MPNowPlayingInfoCenter, it responds but after a few seconds.
Has anyone else experienced this or have any idea what the culprit might be here?
You shouldn't use any graphics code from the background - iOS will kill your app if you do so too much as it takes away from the resources available to foreground apps. It'll also cripple your other background routines.

Resources