【发布时间】:2017-05-18 13:09:33
【问题描述】:
我有一个用 Swift 开发的 iOS 应用程序。我的应用目前在 Swift 2 中,但我将 Xcode 8 与 Swift 3 一起使用。该应用配置为使用旧版 Swift 语言版本。
直到最近,该应用程序才能正常运行。
应用程序要求始终使用该位置的正确权限,并且自动设置正确设置为始终。
我更新了生产应用程序的签名身份,该应用程序停止接收位置更新通知,但仍在开发模式下工作(从 xcode 启动)。
现在我撤销并更新了生产和开发证书,并且应用程序在后台时不会更新位置,而自动设置设置为始终。
应用程序已正确安装,所以我猜证书没问题,但我不明白为什么该位置没有在后台更新。
我在装有 IOS 10.2 的 iPhone 7 上运行该应用程序,xcode 会自动管理签名。
这是我的位置管理器配置:
public class LocationManager : NSObject, ModuleManager, CLLocationManagerDelegate {
/// The core location manager
let coreLocationManager: CLLocationManager
public var datas: JSONable? {
get {
return LocationDatas(locations: self.locations)
}
set {
self.locations = newValue == nil ? [Location]() : newValue as? [Location]
}
}
/// The list of locations to send
private var locations: [Location]?
/// The last location
public var lastLocation: Location? {
return self.locations?.last
}
public override init() {
self.coreLocationManager = CLLocationManager()
if #available(iOS 9.0, *) {
self.coreLocationManager.allowsBackgroundLocationUpdates = true
}
// The accuracy of the location data.
self.coreLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
// The minimum distance (measured in meters) a device must move horizontally before an update event is generated.
self.coreLocationManager.distanceFilter = 500; // meters
self.locations = [Location]()
super.init()
self.coreLocationManager.delegate = self
self.locationManager(self.coreLocationManager, didChangeAuthorizationStatus: CLLocationManager.authorizationStatus())
}
// MARK: - CLLocationManager Delegate
public func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
NSLog("location update")
guard locations.count > 0 else {
NSLog("Module Location -- no location available")
return
}
// Add all location waiting in the list to send
self.locations?.appendContentsOf(locations.map { Location(cllocation: $0) })
SDKManager.manager?.sendHeartbeat()
}
public func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
switch CLLocationManager.authorizationStatus() {
case .NotDetermined:
if #available(iOS 8.0, *) {
self.coreLocationManager.requestAlwaysAuthorization()
} else {
self.coreLocationManager.startUpdatingLocation()
}
case .Denied, .Restricted:
NSLog("Module Location -- access denied to use the location")
case .AuthorizedAlways:
NSLog("AuthorizedAlways")
self.coreLocationManager.startUpdatingLocation()
//self.coreLocationManager.startMonitoringSignificantLocationChanges()
default:
break
}
}
public func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
NSLog("Module Location -- error : \(error)")
}
}
locationManager 函数不在后台调用。
这是我的 info.plist:
这是手机上的授权:
位置小箭头始终存在,但没有记录位置更新。
【问题讨论】:
-
您是否每次都设法调用 startUpdatingLocation()?
-
是的,始终记录 AuthorizedAlways。
-
您收到“允许位置”警报了吗?
-
是的,我收到了警报,我说是的。
标签: ios swift swift3 cllocationmanager