No sound after waking up - ios

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.

Related

app goes into background mode after running video for sometime

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.

how to check what is killing my audio amplifier app? (ios, objective C)

I have an ios app that takes audio from the phone microphone, performs some processing on the mic data in real time and sends the result to headphones
In Project -> Capabilities -> Background modes, I have selected Audio, AirPlay and Picture in Picture
I want the app to continue to read microphone data and send audio to headphones when the app is in background (user presses home button) and when the phone screen is locked using the lock button
All of this is happening, so I don't think there are any problems with the app permissions, but I have noticed that after the app is backgrounded, it suddenly gets killed, usually in less than a minute
I managed to catch an instance of the app getting killed in the background in the xcode console and the message was
Message from Debugger: terminated due to signal 9
Looking around in google indicates that this simply means that the app was destroyed by the OS using SIGKILL
Is there any way to find out why the app was killed? Is it just impossible to keep the app running in background for a long period? Before I enabled Audio, AirPlay and Picture in Picture background mode, the audio used to stop as soon as I pressed the home button or the screen lock button. I am assuming that since the audio keeps running when I press the home button now implies I am indeed able to run mic/speaker in the background if I have to, and there are music players as well as audio recorder apps that work in the background until the user specifically closes them.
How can I find out the exact reason why my app is getting closed automatically, and what can I do to keep it running in the background indefinitely until the user closes it?
After you installed your app through xcode, run it normally (not by run in xcode), Let it crash. Then connect the phone, go to xcode -> Window -> Devices and Simulators -> View Device Logs. Then find the most recent crash.
Your particular problems sounds to me like overuse of CPU. App in background cannot utilize more than 80% (IIRC) of device CPU for extended periods of time (around one minute) or it will be killed by the system. If that is your case you simply need to optimize your code to not hog the CPU.

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?

iOS App prevents device from sleep mode

I've a really strange behavior of my iOS app. It prevents the device from going to standby. I've already searched if there is anywhere the idleTimeDisabled flag set, but this isn't the case. The idle timer inside the settings app is set to 2 minutes and works within other apps. The device isn't jailbroken and the even restarting the device didn't help. The app was written by somebody else and I'm new to it. So in the moment I don't have any idea what to look for. Has anybody of you an idea, why this could be the case or how I could figure out what's the reason for this behavior?
Thank you very much!
If your app is using AVPlayer or some other similar AVFoundation functionality, this can be the cause.
If AVPlayer is playing a video, a device will not go to sleep while a video is playing.
If the video is playing in a loop, the device will never go to sleep.
Edit:
With iOS 12 this is now possible by setting
player.preventsDisplaySleepDuringVideoPlayback = false
Put this line in your ViewController that require not being in sleep mode
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most
applications should let the system turn off the screen when the idle
timer elapses. This includes audio applications. With appropriate use
of Audio Session Services, playback and recording proceed
uninterrupted when the screen turns off. The only applications that
should disable the idle timer are mapping applications, games, or
similar programs with sporadic user interaction.
Make sure you are not "testing" with your Xcode. Because it will always remained as turn on status as long as you plugin your iPhone with a cable.

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