iphone - Black screen after applicationWillEnterForeground -


seems have problem multitasking in ios app. have nstimer running, updates things on screen , nstimer fired once after defined time interval.

the problem is: want react on fire-event. whether app in foreground or not.

i used following code able track timer:

-(void)backgroundthreadstarted {   nsautoreleasepool* thepool = [[nsautoreleasepool alloc] init];    // create scheduled timer   nstimer *timer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(backgroundthreadfire:) userinfo:nil repeats:yes];   [[nsrunloop currentrunloop] addtimer:timer formode:nsdefaultrunloopmode];    m_isbackgroundthreadtoterminate = no;    // create runloop   double resolution = 300.0;   bool isrunning;   {     // run loop!     nsdate* thenextdate = [nsdate datewithtimeintervalsincenow:resolution];      isrunning = [[nsrunloop currentrunloop] runmode:nsdefaultrunloopmode beforedate:thenextdate];      // re-create autorelease pool whilst program running     [thepool release];     thepool = [[nsautoreleasepool alloc] init];               } while(isrunning==yes && m_isbackgroundthreadtoterminate==no);    [thepool release]; }  -(void)backgroundthreadfire:(id)sender {   // repeated work every 1 second here    // when thread terminate, call [self backgroundthreadterminate];  }  -(void)backgroundthreadterminate {   m_isbackgroundthreadtoterminate = yes;   cfrunloopstop([[nsrunloop currentrunloop] getcfrunloop]); } 

(found here: http://www.cocoadev.com/index.pl?runloop)

i'm calling backgroundthreadstarted on -(void)applicationdidenterbackground:(uiapplication *)application , backgroundthreadterminate on - (void)applicationwillenterforeground:(uiapplication *)application , able track timer. works great.

unfortunately after returning app, whole screen black. tried different solutions , googled lot neither worked.

if minimize app while seeing black screen able see app while animating background.

what missing?

if don't backgroundthread stuff, screen shows normal. then, i'm not able track timer.

thanks in advance!

you're using code appkit (os x) not uikit (ios).

you should looking backgrounding api involve handling didenterbackground , in there creating background task beginbackgroundtaskwithexpirationhandler:

background threads aren't necessary (they're things running in background of application, while application still running). background tasks way of letting regular application code run (sans ui interaction) when application no longer in foreground. not able communicate user (the api meant more letting upload finish after leaving application), outside of local notification service. , task limited ten minutes after being backgrounded.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -