Constantly tracking user location on iOS

后端 未结 4 488
花落未央
花落未央 2021-02-09 05:09

I need to constantly monitor the position of an user to notify him when he gets near something interesting. Which is the correct way to achieve this?

I have not been abl

4条回答
  •  醉话见心
    2021-02-09 05:46

    You can set up monitoring location stuff in you VC as below

    in viewDidLoad method do as below

    CLLocationManager locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;(Accuracy according to your need)
    [locationManager startUpdatingLocation];
    

    than you have to overrite below two optional delegate methods of CLLocationManagerDelegate protocol

    for iOS6+

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

    and for iOS 2 to 6

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    

    in these methods you will get updated location. use it as you want. every time location updated these method get calls.

提交回复
热议问题