ios - NSTimer does not stop when invalidate -


i want check if application idle (user doesn't take action last 30 minutes) , log out user.

for have event manager resets timer.

- (void)sendevent:(uievent *)event {           if(event == nil) {         [self resetidletimer];     } else {         [super sendevent:event];          // want reset timer on began touch or ended touch, reduce number of timer resets.         nsset *alltouches = [event alltouches];         if ([alltouches count] > 0) {             // alltouches count ever seems 1, anyobject works here.             uitouchphase phase = ((uitouch *)[alltouches anyobject]).phase;             if (phase == uitouchphasebegan || phase == uitouchphaseended)                 [self resetidletimer];         }     } }  - (void)resetidletimer {     if (self.idletimer) {         [self.idletimer invalidate];         self.idletimer = nil;     }      nsinteger maxtime = 60*30; //30 minutes      self.idletimer = [nstimer scheduledtimerwithtimeinterval:maxtime target:self selector:@selector(checkifidletimerexceeded) userinfo:nil repeats:no]; } - (void)checkifidletimerexceeded {      theprofilemanager = [[profilemanager alloc] init];     theprofile = [theprofilemanager getprofile];      if( ! [[theprofile getstatus]isequaltostring:@"u1"]) {         if( ! [[theprofile gettheuser] isunlimitedlogin]) {             theprofile = nil;             theusermanager = [[usermanager alloc] init];             [theusermanager setcurrentuser:[theprofile gettheuser]];             [theusermanager setcurrentuseraccount:[[theprofile gettheuser] gettheuseraccount]];             [theusermanager setcurrentusersettings:[[theprofile gettheuser] gettheusersettings]];             [theusermanager logoutcurrentuser];              [[menuitemdatamanager alloc] deletejsondata];              nsnotification *msg = [nsnotification notificationwithname:@"leftpanelmsg" object:[[nsstring alloc] initwithformat:@"home"]];             [[nsnotificationcenter defaultcenter] postnotification:msg];              [self performselector:@selector(loadhomeview:) withobject:nil afterdelay:0.5f];         }     }     [self resetidletimer];  } 

the checkifidletimerexceeded log out process.

problem: after 15 minutes touch screen, resetidletime called , should restart new nstimer. after 15 minutes application logs user out.

thanks help.

andré.

as per requirement of touches event. should this:

 nsset *alltouchevents = [event alltouches];     if ([alltouchevents count] > 0) {         // alltouchevents count ever seems 1, anyobject works here.         uitouchphase phase = ((uitouch *)[alltouchevents anyobject]).phase;         if (phase == uitouchphasebegan || phase == uitouchphaseended)             [self resetidletimer];     } 

and in resetidletimer, the

self.idletimer = [nstimer scheduledtimerwithtimeinterval:maxtime target:self selector:@selector(checkifidletimerexceeded) userinfo:nil repeats:no]; 

should like

self.idletimer  = [nstimer scheduledtimerwithtimeinterval:maxtime target:self selector:@selector(checkifidletimerexceeded:) userinfo:nil repeats:no];  

and checkifidletimerexceeded should like:

-(void) checkifidletimerexceeded :(nstimer*)timer     {         //do process , invalidate after completion          [timer invalidate];      } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -