iphone - Background location service tracking not stopping when i "OFF" the UISwitch -


am using uiswitch turn "on" , "off" the location services. when switch "on" uiswitch location services start to track teh location. can come out app , location services running good. problem when switch "off" tracking , move view controller location tracking still in "on" state , not stopping tracking. below code.

-(void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations{     cllocation* location = [locations lastobject];     latdeg = location.coordinate.latitude;     longdeg = location.coordinate.longitude; }  -(ibaction)starttracking:(id)sender{  if(starttrackingbutton.on){ [locationmanager startupdatinglocation]; [[nsuserdefaults standarduserdefaults] setbool:starttrackingbutton.on forkey:@"switchvalue"]; [[nsuserdefaults standarduserdefaults] synchronize]; } else{     [[nsuserdefaults standarduserdefaults] setbool:starttrackingbutton.on forkey:@"switchvalue"];   [[nsuserdefaults standarduserdefaults] synchronize];   [locationmanager stopupdatinglocation];  } }  - (void)viewdidload{    [super viewdidload];    [starttrackingbutton seton:[[nsuserdefaults standarduserdefaults] boolforkey:@"switchvalue"]];    locationmanager = [[cllocationmanager alloc] init];    [locationmanager setdelegate:self];    [locationmanager setdesiredaccuracy:kcllocationaccuracybest];    [self.navigationitem sethidesbackbutton:yes]; } 

any suggestions?

i'm going assume starttrackingbutton uiswitch. if case, should checking ison property.

if (starttrackingbutton.ison) {     [locationmanager startupdatinglocation];     [[nsuserdefaults standarduserdefaults] setbool:starttrackingbutton.on forkey:@"switchvalue"];     [[nsuserdefaults standarduserdefaults] synchronize]; } else {     [[nsuserdefaults standarduserdefaults] setbool:starttrackingbutton.on forkey:@"switchvalue"];     [[nsuserdefaults standarduserdefaults] synchronize];     [locationmanager stopupdatinglocation]; } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -