How to stop multiple times method calling of didUpdateLocations() in ios

前端 未结 10 1171
無奈伤痛
無奈伤痛 2020-11-28 06:45

This my code......

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
 {

    location_updated = [locations lastObj         


        
10条回答
  •  广开言路
    2020-11-28 07:29

    You could set a flag (Bool). When you instantiate your locationsManager set flag = true then when locationManager:didUpdateLocations returns inside a code block that you want to run only once set flag = false. This way it will only be run the once.

     if flag == true {
         flag = false
        ...some code probably network call you only want to run the once 
        }
    

    locations manager will be called multiple times but the code you want to execute only once, and I think that is what you are trying to achieve?

提交回复
热议问题