The timer rotates periodically after returning from the background

I have a compatibility issue with my latest version of the app. I have a timer that starts in the AppDelegate that calls a function every 30 seconds to load a new declaration. I think this is the culprit in this crash. Using Crittercism I've had over 20 crashes for 13 users. Users are mostly using iOS 6 or some variants of it. Here is the log he gave me:

SEGV_ACCERR

0 libobjc.A.dylib 0x3acd25b0 objc_msgSend + 16

1 Base 0x3394b277 __NSFireDelayedPerform + 451

2 CoreFoundation 0x330125df CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 15

3 CoreFoundation 0x33012291 __CFRunLoopDoTimer + 273

4 CoreFoundation 0x33010f01 __CFRunLoopRun + 1233

5 CoreFoundation 0x32f83ebd CFRunLoopRunSpecific + 357

6 CoreFoundation 0x32f83d49 CFRunLoopRunInMode + 105

7 GraphicsServices 0x36b452eb GSEventRunModal + 75

8 UIKit 0x34e99301 UIApplicationMain + 1121

9 AutoScene 0x000031b7 main (main.m: 7)

My timer:

[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(resetAdTimer) userInfo:nil repeats:YES];

      

I don't know if there was the same problem, but I experienced a time when I return to the application from the background and it just hangs. It seems to hang for 30 seconds which makes me believe this is the timer code.

Is this really a bad way to manage ad serving? Does the timer code light up when it lasts a long time in the background?

Thank you for your help!

+3


source to share


1 answer


You must invalidate the timer in appWillResignActive and re-create it in appWillBecome. From the docs ...

- (void)applicationWillResignActive:(UIApplication *)application 

      



You should use this method to pause running tasks, disable timers, and lower your OpenGL ES frame rate. Games must use this method to pause the game. An application in an inactive state should perform minimal work while it waits for a transition to an active or background state.

+2


source







All Articles