我有一个使用Swift开发的iOS应用程序。我的应用程序目前采用Swift 2,但我正在使用带有Swift 3的Xcode 8。该应用程序配置为使用旧版Swift语言。
直到最近,该应用程序一直正常工作。
该应用程序请求始终使用位置的正确权限,并且授权已正确设置为始终使用。
我更新了生产应用程序的签名标识,然后该应用程序停止在位置更新时收到通知,但在开发模式下仍在工作(从xcode启动)。
现在我吊销并更新了生产和开发证书,但该应用程序在后台不更新位置,尽管授权已设置为始终使用。
该应用程序已正确安装,因此我猜测证书是没有问题的,但我不明白为什么位置没有在后台更新。
我在iPhone 7上运行该应用程序,使用的是IOS 10.2,并且xcode自动管理签名。
以下是我的位置管理器配置:
以下是我的 info.plist:
以下是手机上的授权信息:
小的位置箭头一直存在,但没有位置更新被记录。
直到最近,该应用程序一直正常工作。
该应用程序请求始终使用位置的正确权限,并且授权已正确设置为始终使用。
我更新了生产应用程序的签名标识,然后该应用程序停止在位置更新时收到通知,但在开发模式下仍在工作(从xcode启动)。
现在我吊销并更新了生产和开发证书,但该应用程序在后台不更新位置,尽管授权已设置为始终使用。
该应用程序已正确安装,因此我猜测证书是没有问题的,但我不明白为什么位置没有在后台更新。
我在iPhone 7上运行该应用程序,使用的是IOS 10.2,并且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:
![enter image description here](https://istack.dev59.com/nckmc.webp)
![enter image description here](https://istack.dev59.com/FXocI.webp)