Azi*_*lah 8 cllocationmanager ios ios-simulator swift location-services
我在AppDelegate文件中使用Swift在我的应用程序中添加了CLLocationManager.
在Appdelegate.swift文件中,
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var locationManager: CLLocationManager!
Run Code Online (Sandbox Code Playgroud)
在didbecomeActive方法中:
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()
}
Run Code Online (Sandbox Code Playgroud)
如果我使用startUpdatingLocation,didUpdateLocations方法被调用,但不是startMonitoringSignificantLocationChanges.
为什么没有被要求startMonitoringSignificantLocationChanges.我在ios模拟器中测试这个.我不知道如何检查设备.
mic*_*rus 21
它正在工作,但是很难触发显着的位置变化 - 通常在设备更换单元塔时发生 - 我不认为可以使用模拟器.
你可能不得不坐上自行车/汽车并且行驶至少几公里.
你可以使用一个技巧,这将触发重大的位置变化:
在iPhone上以几秒的间隔开启和关闭Airplaine模式,它应该诱使设备认为它改变了单元塔并触发了重要的位置变化.
| 归档时间: |
|
| 查看次数: |
5362 次 |
| 最近记录: |