iphone - NSTimer in background -
i new in iphone development. have issue . using nstimer update uilabel in every second. have 2 problem :
- when app goes in background , after when open app . app goes hangs.
- 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
Post a Comment