iPhone simulator minimizes the application - iphone

I'm debugging my app with the simulator. And for some moment in concrete situation the app gets mimimized. I think there is some problem in my code (Most likely some variable is not initialized, because sometimes everything works) . But how can I catch this moment.
In xcode is still written that the program is running and I can put breakpoints and the will trigger.
And if i will reopen my application it will continue working...
When using device the are no problems too...
How can i catch this moment and pause the program to view a callstack.
EDIT
I Think the problem is here:
Objective-c singleton object does not working as expected

You could try catching it in the - (void)applicationDidEnterBackground:(UIApplication *)application-methode in the app delegate, at least then you will see specifically when it happens.

Related

Code To Crush A Swift Application on Startup/launch

In an Xcode project, how can I write any Swift codes that crashes the Application on startup once it’s launched/run on the simulator or device?
You can follow app lifecycle events in your UIApplicationDelegate. For example application(_:didFinishLaunchingWithOptions:)) is called, when the app started and a little time before it's visible. You can put the crashing code there.
There are a few ways to crash the app. One of them is to call fatalError().

App crashes on iPhone but not simulator or iPad?

I have developed an app for the iPhone and everything is going well. Today i decided to prep it for the upcoming iOS 7 launch, and the app worked as intended until I tried it on my iPhone 5. Whenever it crashes it throws some exc_bad_access codes.
It doesn't crash in the simulator or on my iPad which is running iOS 6.1.
I hope you guys can help me.
Btw, i get different exc_bad_access codes every time, but this is one of them.
http://gyazo.com/43716488eb120e44e74f76cd4d659076
You have thread-related race conditions. Note how it's crashing in thread 7? Race conditions will express themselves differently on different hardware since the timing can be dramatically different.
tableView:cellForRowAtIndexPath: is a UIKit method that must run on the main thread. In your case, it's running on thread 7, which is itself probably the cause of your problem. I suspect you're doing something like calling reloadData on a background thread.
Note that you're also directly accessing your ivars rather than using accessors. That tends to make threading problems harder to track down and manage. You should always be using accessors except in init, inside of accessors, and in dealloc.

iOS exit(0) strange behavior

In application that I work on it, I need to close it from code. I'm using exit(0) for that.
Yes, I know that i shouldn't close application from code
When I close application in this way, and run it again, there is some strange behaviur - application doesn't start nor from splash screen, like new instance of app, neither from last view, like application turning back from background.
Instead, for a second some random, non-interactive view of my app is appearing, and after this splash screen start to run.
I'm confused because I cannot find source, and how to fix this ugly bug. Can you help me?
This is exactly the problem with exit(0). You get weird multitasking behaviour and all sorts of other problems.
You simply can't terminate your application in code. You should explain to us why you think you need to quit programmatically so we can help you find an alternative solution.
From Technical Q&A QA1561
There is no API provided for gracefully terminating an iOS application.
Do not call the exit function. Applications calling exit will appear
to the user to have crashed, rather than performing a graceful
termination and animating back to the Home screen.
Additionally, data may not be saved, because
-applicationWillTerminate: and similar UIApplicationDelegate methods will not be invoked
if you call exit. If during development or testing
it is necessary to terminate your application, the abort function, or
assert macro is recommended.
Instead of
exit(0)
try this:
[[UIApplication sharedApplication] performSelector:#selector(terminateWithSuccess)];

How to debug EXC_BAD_ACCESS on device only

I have some code that returns a struct containing 2 objects (declared as id).
When trying to use one of the objects I get an EXC_BAD_ACCESS and the app crashes. This only happens on the device (ipad) not in the simulator.
I have set NSZombieEnabled to YES, however no information is written to the console.
I don't know if it's a problem that I'm using a workspace in Xcode 4, one project for my app, and another that builds a library which is used in my app. The EXC_BAD_ACCESS is occurring in the second project, so I don't know if NSZombieEnabled will apply to the second project?
How do I solve this? Especially as I it only happens on the device (even goes as planned on the simulator), and it is in the second project?
EDIT: This is the method where the EXC_BAD_ACCESS occurs, on line 62, on sortRange.lower –
NSZombieEnabled only works on the simulator, not on the device, so it's probably hiding the problem. Run Product > Analyze (⇧⌘B) for clues. It's harder to say more without looking at the code. As Mihai says, your objects are probably over released, which is the most common cause of EXC_BAD_ACCESS.
It seems that one of your objects is autoreleased before you are trying to access it. As the iPad has less memory than the computer you are running it on it get's released faster so that's why it's not available. Try NSLog both objects just before the line you are getting the error and see wich one of them is the problem and than trace back to it's origin and retain it somehow. Also don't forget to release it after you are done using it. Some example code would be useful.

App crashes on backgrounding because of SimpleAudioEngine

So I׳m trying to play some effects in my Cocos2D game using SimpleAudioEngine , but after I have added them my app crashes when it goes to background (multitasked).
I searched for this problem in the internet but all the solutions that I found didn't work for me. What I did find out is that this problem happens because my app is somehow trying to play sounds when backgrounded.
In console it shows me (which is the same error I found other people had):
sgx error (background gpu access not permitted):
And another thing, when I run my app on the simulator, or even on my device while debugging carefully (going line-by-line with XCode while the app is running) this doesn't happen.
I just had this issue. I resolved it by having a bool to check if the app is running or in background that I set to true when the app goes to foreground ( applicationWillEnterForeground ) and that I set to false when the app goes to background ( applicationDidEnterbackground ) . So using the bool you can tell if the app is in the background and if it is, I just exit out of drawView function in EAGLView (thus not doing any graphics rendering which was causing the error).
I am a very dodge programmer but that method has worked for me and I hope it works for someone else. I did not need to unload and reload my sounds or anything and my app now has Multitasking XD
I was experiencing this, on about 25% of the occasions that my application re-entered the foreground. Like you, when I removed the sounds, the problem went away. That is how I came across your question here.
I may have found a solution to this. I have made what appears to be an unrelated change, but the problem seems to have gone away. Now, when my app enters the background, I invalidate my main scheduled timer. When my app re-enters the foreground, I then re-schedule the timer (after reloading my sounds, which I completely shut down on entering background).
So far, the problem has not come back. I would be interested to know if this helps.
I just resolved this issue on my end. Here's what was wrong in my case and, from what I can tell from the other answers and comments on this page, many other people's case as well:
By default, when I started my project, CCDirector::sharedDirector()->pause(); and CCDirector::sharedDirector()->resume(); were both being called twice, once by (void)applicationWillResignActive:(UIApplication *) and (void)applicationDidBecomeActive:(UIApplication *) respectively in AppController.mm, and once by AppDelegate::applicationDidEnterBackground() and AppDelegate::applicationWillEnterForeground() respectively in AppDelegate.cpp.
Make absolutely sure that these methods are only being called once, in AppController.mm. In AppDelegate.cpp, instead make sure that you are calling CCDirector::sharedDirector()->stopAnimation(); in place of CCDirector::sharedDirector()->pause(); and CCDirector::sharedDirector()->startAnimation(); in place of CCDirector::sharedDirector()->resume();.
Hope that's helpful to anyone else stuck in this crappy situation!
Are you sure it's related to audio? "background gpu access" sounds like it's using OpenGL.
I had the same issue in my application and spent some 4 hours to find out. Going background was OK the first time, but crash application the second time. With a short error message related to OpenGL. I had the same questions: how audio can crash graphics. But it wasn't a question of audio, but a question of notifications...
I discovered that going foreground was creating 2 timers in my custom level meter class.
I had registered UIApplicationWillEnterForegroundNotification and UIApplicationWillResignActiveNotification. Then, going background invalidated only one, since I registered only on notification... That was it!
One need's count its notifications!