iphone - NSTimer in background -


i new in iphone development. have issue . using nstimer update uilabel in every second. have 2 problem :

  1. when app goes in background , after when open app . app goes hangs.
  2. if goes next or on other ui screen wen comes on timer screen label again shows 0.

can me.

code using :

timer = [nstimer scheduledtimerwithtimeinterval: 1.0 target:self selector:@selector(updatecountdown) userinfo:nil repeats: yes];  -(void) updatecountdown {     secondsleft--;      //nits testing     if(secondsleft == 1)     {          [self.view addsubview:recipepage6view.view];     }        if (secondsleft<0)     {         [timer invalidate];         timer=nil;         lbldisplaytimer.text =@"00:00:00";      }     else     {         hours = secondsleft / 3600;         minutes = (secondsleft % 3600) / 60;         seconds = (secondsleft %3600) % 60;          lbldisplaytimer.text = [nsstring stringwithformat:@"%02d:%02d:%02d", hours, minutes, seconds];          //lbldisplaytimer.text = [nsstring stringwithformat:@"%02d:%02d",minutes,seconds];      }  } 

you need set special background timer task , not have nstimer on main run loop gets suspended in background. documentation on how here


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -