StartMonitoringSignificantLocationChanges not working in swift

I added CLLocationManager to my application using Swift in the AppDelegate file.

In the Appdelegate.swift file

import CoreLocation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { var locationManager: CLLocationManager! 

In the didbecomeActive method:

 func applicationDidBecomeActive(application: UIApplication) { if((locationManager) != nil) { locationManager.stopMonitoringSignificantLocationChanges() locationManager.delegate = nil locationManager = nil } locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.activityType = CLActivityType.OtherNavigation locationManager.requestAlwaysAuthorization() locationManager.startMonitoringSignificantLocationChanges() } 

If I use startUpdatingLocation , the didUpdateLocations method didUpdateLocations called, but not for startMonitoringSignificantLocationChanges .

Why it is not called for startMonitoringSignificantLocationChanges . I am testing this in an ios simulator. I do not know how to check the device.

+8
ios swift ios-simulator cllocationmanager location-services
source share
2 answers

It works, but it’s very difficult to cause significant changes in location β€” this usually happens when the device changes its cell towers β€” I don’t think it’s possible to do this with a simulator.

You may have to ride a bike / car and travel a few kilometers.

There is a trick that you can use, which will lead to a significant change in location:

Switch Airplaine mode on your iPhone on. and off with a few second intervals, he must trick the device into believing that he has changed his cell towers and is initiating a significant change in location.

enter image description here

+20
source share

In your simulator, go to Debug-> Location-> Custom and change the location, then check it.

+3
source share

All Articles