9

I'd added CLLocationManager in my app 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, didUpdateLocations method gets called, but not for startMonitoringSignificantLocationChanges.

Why it's not getting called for startMonitoringSignificantLocationChanges. I'm testing this in ios simulator. I don't know how to check in device.

Nazik
  • 8,696
  • 27
  • 77
  • 123
  • possible duplicate of: http://stackoverflow.com/questions/8682683/can-i-test-significant-change-with-xcode-simulator – adolfosrs Dec 15 '15 at 10:18

4 Answers4

23

It's working, but it's really hard to trigger significant location changes - it usually happens when the device is changing cell towers - I don't think it's possible to do with the simulator.

You'd probably have to get on a bike/car and travel AT LEAST a few kilometres.

There's a trick you can use though, that will trigger significant location change:

Switch Airplaine mode in your iPhone on and off with a few second intervals repeatedly, it should trick the device into thinking that it changed cell towers and trigger the significant location change.

enter image description here

michal.ciurus
  • 3,616
  • 17
  • 32
3

In your simulator, goto Debug->Location->Custom and change location, then test it.

Rujoota Shah
  • 1,251
  • 16
  • 18
2

In your simulator, select Features -> Location -> Freeway Drive

Wait a bit for startMonitoringSignificantLocationChanges to trigger didUpdateLocations.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Riajur Rahman
  • 1,976
  • 19
  • 28
0

Note: Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner. startMonitoringSignificantLocationChanges()

Samira
  • 844
  • 13
  • 17