2015-12-03 44 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]; 
    { 
} 
相關問題