Using the new CLVisit in CoreLocation

I did not say anything about CLVisit, so I'm trying to learn this technology myself.

Does anyone know why it is not working? All .plist keys are installed and working.

class ViewController: UIViewController,CLLocationManagerDelegate {

var manager:CLLocationManager!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    manager = CLLocationManager()
    manager.delegate = self
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.requestAlwaysAuthorization()
    manager.startMonitoringVisits()


}


func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {

}
func locationManager(manager: CLLocationManager!,
    didVisit visit: CLVisit!)
{
    println("visit: \(visit.coordinate.latitude),\(visit.coordinate.longitude)")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}
+4
source share
3 answers

I assume that you are trying to get these delegate calls when the application is in the background; however, you create an instance of CLLocationManager in the view controller that will not be created (afaik).

This works for me (I use iOS 8, beta-2, on the iPad mini 2nd gen): set the key NSLocationAlwaysUsageDescription, turn on the "Location Updates" background mode in Capabilities and enable the following in AppDelegate:

let locationManager = CLLocationManager()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    locationManager.delegate = self
    locationManager.requestAlwaysAuthorization()
    locationManager.startMonitoringVisits()

    return true
}

func locationManager(manager: CLLocationManager!, didVisit visit: CLVisit!) {
    println("Visit: \(visit)")
    // I find that sending this to a UILocalNotification is handy for debugging
}

: , https://github.com/mloughran/CLVisit-POC.

+4

. , CLVisit , . , .:)

CLVisit, "", , , WWDC, , CLVisit , , . , . , , , .

NSLog , CLVisits, , Core Data, :

    Visits *thisVisit = [NSEntityDescription insertNewObjectForEntityForName:@"Visits" inManagedObjectContext:[self managedObjectContext]];
    thisVisit.arrivalDate = visit.arrivalDate;
    thisVisit.departureDate = visit.departureDate;
    thisVisit.latitude = [NSNumber numberWithDouble:visit.coordinate.latitude];
    thisVisit.longitude = [NSNumber numberWithDouble:visit.coordinate.longitude];
    [self saveContext];

, , .

EDIT: . , API. , -. - , , ...

https://github.com/steveschauer/TestCLVisit

+7

, API . AppDelegate, . , , .

. ( 30 ). , , . . .

: xx.11852879438132 : -xxx.7792256808099 : 2014-06-25 12:19 PM : 2014-06-25 16:44

: xx.1185726857039 : -xxx.7793685278068 : 2014-06-26 5:59 AM departureDate: farFuture

.

+1

Source: https://habr.com/ru/post/1545590/


All Articles