iPod app stops responding after iPod returns from standby mode - iphone

The GUI of my application stops responding after the iPod has been in standby mode. The application I have made is based on the "Utility application" template from the wizard in xcode - but the original application still works after the iPod returns from standby.
My application plays music (AudioUnit) and when the iPod enters standby the music stops but when the iPod leaves standby mode the music starts playing again but as mentioned the GUI does not respond to touches anymore. All I can do is to shut it down.
I have read about this problem here:
What happens to an iPhone app when iPhone goes into stand-by mode?
but that did not help me enough to solve the problem.

Sounds like your Audio Unit has been stopped.
If your GUI relies on the AU's progress then that would explain the problem.
Check your AU's state in applicationDidBecomeActive.
I didn't think standby mode stopped AUs, I thought only audio interruptions
did that. Anyway, you should probably look at AudioSessions as well, as you'll
find that phone calls, alarms, SMSs and ipod music will also stop your Audio Unit.
Good luck.

Actually, I've been running into this problem on the iPod application itself, in just general daily use. That is, if you are using the 3.0 firmware OS, then this is most likely a bug in the iPhone. I guess you can relax, and know that it's probably not your own code that is causing the problem. I'd file a radar ticket with Apple if you haven't already so that they can address it in the next bug fix release.

It all happens just because I have an UISlider in an UIToolbar. If I remove the UISlider from my GUI it still responds after waking up from standby/sleep mode.
Can someone explain me why that causes this problem (is it a bug in Apple's code)?

The solution is here:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/4558-app-crashing-upon-quit.html
Simply don't put a slider in a toolbar. Make a work around so it looks like the slider is in the toolbar instead. It is a bug in Apple's code.

Related

When a game goes into background on iOS, what should I do to avoid getting stuck?

I am doing a game on iOS using starling AIR. It can running on iPhone and iPad. It contains a lot of animation and needs to connect to the server when playing.
The problem is, when the game enter background or the screen locked for a while, sometimes the game will stuck, sometimes it will restart, sometimes it will running normally.
I have read the AIR iOS – Background Behavior.
I know that when the application is suspended, os will handle memory optimization, it depends on the apps running foreground.
But what should I do when the game enter background ?
Let the game restart or run normally is fine, but avoiding stuck.
Thank you for all answers.
What you need to do is save your application state when your app is suspended, and restore it when its restored. There's a failry lengthy tutorial on Adobe Devnet showing how they recommend doing that.
Saving State in AIR Applications(Link)
"What to Do When Moving to the Background" and "Memory Usage for Background Apps" section of the documentation clearly explains this.

GUI is stuck with uibackgroundmodes= voip, audio

I have tabbar-based application. When I put in my plist UIBackgroundModes (my application is supposed to support voip), the GUI doesn't load. It sucks on Splash screen and doesn't load the first tab view. When i remove the UIBackgroundModes property from info.plist, it works fine. More than that, pressing the home button when it stuck does nothing. Did somebody encountered a similar problem? (The problem exists on simulator)
Thanks,
Nava
It appears, that the problem happens on Simulator only, it works on the device... So the solution (temporary one) is not to put UIBackgroundModes into info.plist for simulator version.
You are responsible for loading/unloading the interface when going in and out of the background mode. You'll also need to update the interface accordingly when coming out of background.
iOS helps a bit by taking a screenshot before putting the app in background and displaying it when getting the app to foreground (a bit like Default.png when starting the app) and also some UIImage caching.
It might be worth sharing some code.
Supporting Background State Transitions
Supporting the background state transition is part of the fundamental architecture for applications in iOS 4 and later. Although technically the only thing you have to do to support this capability is link against iOS 4 and later, properly supporting it requires some additional work. Specifically, your application delegate should implement the following methods and implement appropriate behaviors in each of them:
application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:
applicationWillResignActive:
applicationDidEnterBackground:
applicationWillEnterForeground:
applicationWillTerminate:
Being a Responsible, Multitasking-Aware Application
Applications that run in the background are more limited in what they can do than a foreground application. And even if your application does not run in the background, there are are certain guidelines you should follow when implementing your application.
Do not make any OpenGL ES calls from your code. You must not create an EAGLContext object or issue any OpenGL ES drawing commands of any kind. Using these calls will cause your application to be terminated immediately.
[...]
iOS Application Programming Guide
I see this bug as well. It's very annoying. It's as if the app is stuck in the simulator and won't keep going. When this happens, I know how to "unstick" it.
In the simulator I just go to menu Hardware > Lock and then unlock the phone again. Now I stop the debugger and start the app again. This seems to kick it back to life.
Fortunately this bug doesn't happen on a real phone, only in the simulator.

How to run my app even after iPhone screen locks?

I want my app (LaunchDaemon) to keep running even if user locks the iPhone. My LaunchDaemon simply check a file and if some condition is true, it displays an Alert to the User. Its working great when iPhone is on Home Screen, but it is not working when user Locks the Screen.
I want something Similar to Alarm app of iPhone which will show an Alert even if the iPhone screen is Locked.
Any suggestions on how to do this? BTW i am developing for JB iPhone.
OS powers down the device and suspends your app after about 30 seconds after screen is locked. However,
if your app is playing a sound OS will not do that. Hence what you need to do is play a silent sound in a loop.
Alright i have solved this problem too.
Here is a very good tutorial on how to prevent deep sleep of iPhone.
Prevent iPhone Deep Sleep
It took me quite sometime to made this work, as NSRunLoop was not running for me automatically.
Hope this will help someone else also.
Best of Luck !!!

MPVolume on ipodtouch/iphone

i'm using the code of this link: http://blog.stormyprods.com/2008/09/proper-usage-of-mpvolumeview-class.html
it is working on an ipod touch, but NOT on iphones.
what can be the reason for that?
Two things:
I think iPhone OS 3.0 does a better job of syncing the MPVolumeView slider with changes to the system volume received from the buttons on side. So the workaround on that blog (listening for NSNotifications) may no longer be necessary.
On the iPhone, volume changes are contextual. If your app is currently playing sound, then hitting the volume buttons (or, presumably, MPVolumeView) affects the volume level of your app's audio. But if your app isn't producing sound, then you are just changing the ringer volume. This might explain why your current code works on touches, which don't have ringers.

IPhone application won't launch correctly

So I'm developing and iPhone game right now and everything has been working just fine when I test it on my first gen iPod touch. Last night, I added in some NSUserDefaults stuff to save a few variables for it. I ran it on the simulator a few times and it worked perfectly, but when I built the app and put it on my iPod, all I got when I launched it was a black screen. Anyone have any ideas? They would be much appreciated, thank you.
I recommend deleting the application from your iPod Touch first then trying to install it again. When are you trying to read from NSUserDefaults? In your applicationWillFinishLaunching call? If so, try to comment that out to ensure that it really is the source of your problem.
You need to run it on the iPod touch with the debugger switched on - you should be able to track this down.
Do you know about setting a breakpoint for exceptions - if you tell the debugger to break on objc_exception_throw it is extreemly useful in these cases.
Do you have a custom Default.png file? If no, then you will see a black screen while your application loads. Depending what type of (possibly unending) operations you are doing on load this might be the reason you are seeing a black screen. Remember the simulator runs on top of the processor in your mac which is significantly faster than the processor in your iPod Touch.