2015-12-03 45 views

回答

1

您可以将该开关绑定到在用户默认设置中设置布尔值的方法(如USER_LOCATION_ENABLED)。

-(void)switchAction:(id)sender { 

    UISwitch *theSwitch = (UISwitch *)sender; 
    if(theSwitch.isOn) { 
     [[NSUserDefaults standardDefaults] setObject:YES forKey:@"USER_LOCATION_ENABLED"]; 
    } else { 
     [[NSUserDefaults standardDefaults] setObject:NO forKey:@"USER_LOCATION_ENABLED"]; 
    } 
    [[NSUserDefaults standardDefaults] synchronize]; 
} 

然后,在你的代码,如果USER_LOCATION_ENABLED设置为true只启动定位服务。

-(void)startLocationServices { 
    if([[NSUserDefaults standardDefaults] objectForKey:@"USER_LOCATION_ENABLED"]) { 
     [locationManager startUpdatingLocation]; 
    { 
} 
相关问题