gSignificantLocationChanges在swif

gSignificantLocationChanges在swif

本文介绍了startMonitoringSignificantLocationChanges在swift中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppDelegate文件中使用Swift在我的应用程序中添加了CLLocationManager。

I'd added CLLocationManager in my app using Swift in the AppDelegate file.

在Appdelegate.swift文件中,

In the Appdelegate.swift file,

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

在didbecomeActive方法中:

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()
}

如果我使用 startUpdatingLocation ,则会调用 didUpdateLocations 方法,但不会调用 startMonitoringSignificantLocationChanges

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

为什么没有调用 startMonitoringSignifi cantLocationChanges
我在ios模拟器中测试这个。我不知道如何检查设备。

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

推荐答案

它正在运行,但很难触发重要的位置更改 - 它通常在设备更换手机信号塔时发生 - 我认为不可能使用模拟器。

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:

反复按几秒钟的间隔开启和关闭iPhone中的Airplaine模式,它应该诱使设备认为它改变了手机信号塔并触发了显着的位置变化。

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.

这篇关于startMonitoringSignificantLocationChanges在swift中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:21