How do I shut down OpenGL tasks in applicationWillResignActive? - ios

I have nearly completed my first app. In testing on the device, I am getting a crash when I press the home button, with the error message
libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
Based on these posts:
https://stackoverflow.com/search?q=how+to+shut+down+OpenGL
OpenGL ES crash on move background, iOS 5.1
I am pretty sure the problem is that my app is an extension of software that uses some sample code involving OpenGL (about which I have very little understanding) and that the OpenGL tasks are not shutting down properly on resignActive.
I tried the following in my AppDelegate with no luck:
- (void)applicationWillResignActive:(UIApplication *)application {
glFinish();
}
My app does not need to save any settings upon exit... it just needs to end.
Can anyone suggest a solution?

I am now working on a Sprite Kit game and I had a similar problem.
Check if you have on the screen the node that tells the FPS, because that might be rendering and causing the crash.. It did for me.
In applicationWillResignActive method I call my pause method as all of you.
*edit - and check for audio playing

To finish program at user push home button ?
on Xcode, choice Target and select Info tab.
Custom iOS Target Properties, add a Key named
Application does not run in background
and set Value
YES
Try it!
p.s. Not necessary write glFinish().

Related

Unity iOS OpenGL app crash

I have an iOS Unity Game developed. In order to help tester to track the bug, I have added one more module which will take the snapshot and then show a view to the tester to Annotate it. I am using Apple's GLPaint example : https://developer.apple.com/library/ios/samplecode/GLPaint/Introduction/Intro.html .
When I start annotating, I pause the Unity game and resume when the annotation is over. But there is one problem, when I try to resume the unity game, the app crashes weirdly with some error GL_INVALID_OPERATION
Check the trace log
Never used Unity, but it smells like the current GL context changes when you bring up the annotation view, and isn't restored properly when you return to the game. Give saving/restoring Unity's GL context a shot (see: EAGLContext +currentContext & +setCurrentContext:).

Launch iOS app faster

I figured out that some iOS apps are launching really faster (e.g. YouTube-from google,Skype,iTunes).
I created an empty application (used standard tabbed application template) and i did not change any code at all, just added splash images. When i tested (tried both developer and Ad-Hoc provisioning profiles to sign to check whether if there any difference), it did not launch as fast as the above mentioned apps.
When i tap the app icon on the device app icon get darker for about 0.2-0.5 seconds and then start showing splash image.
My question is how to make my app launch really fast, and is there any trick to show splash image very quickly? (i wonder how my empty application launches slower than above mentioned apps?)
Thanks
I think you also may be falling for a trick: at least for the iTunes app, Apple is overwriting the splash image with one that looks very much like the app while running, which creates the illusion that the app loads immediately. Try it:
Launch iTunes (or "Music") and start it playing, then go do something else to cause the system to swap the process out as much as possible (say, browse some heavy websites). Then relaunch iTunes and immediately try to pause the audio. On my iPhone 4, it takes about 3 seconds before the controls catch up: the position indicator will jump to the correct location, and until that time, the "play" button is inactive - you can't pause the audio. You're seeing a splash image that is meant to make you think that the app is launching immediately, even though it's really taking a few seconds to launch.
I've also noticed Chrome for iOS doing the same thing. I actually dislike this design decision, because it communicates that the app is ready before you can do anything with it.
i did not changed any code at all just added splash images
The loading images are not intended to show splash images, they are intended to show a static version of your application's interface to give the illusion that your application is loading more quickly than it really is.
Splash images are specifically warned against by Apple in the HIG.
Stop abusing loading images to show splash images, start using them properly, and your application will look as if it is loading more quickly.
link to as few frameworks as possible, we tried this at WWDC and linking to many frameworks creates a noticeable delay even before the main() method is called!
no matter how fast your code itself is!

IOS: turn off camera

In my app I use iphone camera, but the process is very low when I open it; then I want to start the process when I shows a splashscreen.
The problem is that when splashscreen ends I don't want to show camera.
Then while I show splashscreen I want to start process of camera and quit it before splashscreen disappear. Is it possible?
First up, Apple specifically advise against using splash screens in their Human Interface Guidelines document. I don't know if your app would get rejected for it, but best not to try.
Second, it sounds like you need to optimise the startup of your application and probably the first view controller. To do this, you need to put off loading/initialising everything you can until it's actually needed (known as "lazy initialisation). All code in applicationDidFinishLaunching: in your app delegate and your view controller's init method, loadView, viewDidLoad, viewWillAppear, viewDidAppear should be reviewed for stuff that could be done later.

iPhone: Is it possible to close the app rather than run in background when user clicks Home Button?

I have an app which crashes everytime when I resume it.
I want that when user clicks Home button, the app should close rather than go in background mode.
Is that possible?
If yes, please let me know.
If not, what could be the workaround so that my app does not crash when I resume it?
Thanks!
In the plist, set YES to Application does not run in background key.
When ur application is in background, due to memory insufficient, the views (and the objects released in viewDidUnload) might be released. Again when reopen the application, make sure all the required objects are re-initialized.
To opt out of background execution, see this thread... But ideally what you should do is fix the crash and let app user enjoy iOS background feature..
what could be the workaround so that my app does not crash when I
resume it?
Never think of work arounds when you can handle it straight..

Quit app when pressing home

I my testing, when I exit (by pressing the home button) my app, it still is "running" in the background, thanks to the multitasking feature. However, I would like it to quit when the home button is pressed. Is this only happening to me?
Anyway, I have tracked it down to the applicationWillResignActive and the applicationDidBecomeActive methods in the app delegate. These get called for multitasking, but when I want to terminate, the app "resigns active." Any guidance on this issue is greatly appreciated!
Your application can opt out of multitasking (see the appropriate section in the iPhone Application Programming Guide) by adding the UIApplicationExitsOnSuspend key to your Info.plist and setting its value to YES.
In practice, Apple strongly recommends you not do this unless you have a very good reason for this behavior.
I think it's more efficient to suspend an app, when pressing the "Home" button. There's overhead in constantly launching and terminating apps. It's worse for the iOS operating system, and it's worse for user experience - because they need to wait for the app to launch again. Not sure what benefits you gain from terminating an app. If it's for simulation testing, my advice is to avoid that functionality, because your testing environment should be as realistic as possible. If your purpose is to clear cache or to make updates - that can all be done programmatically from subroutines.
Exiting subroutines
applicationWillResignActive
applicationDidEnterBackground
applicationWillTerminate
Entering subroutines
applicationDidBecomeActive
applicationWillEnterForeground
applicatonDidFinishLaunching
If you still insist on terminating an app when the user presses the "Home" button, despite the costs mentioned above - then set the UIApplicationExitsOnSuspend to true in your Info.plist as suggested by Brad Larson.
I wouldn't recommend trying to control the user's HOME button... deciding for them "exit" or "suspend".
I WOULD like to have HOME do an instant EXIT in the iPhone simulator... but haven't found any way to do that.

Resources