gpt4 book ai didi

ios - 应用程序终止时的位置更新

转载 作者:行者123 更新时间:2023-11-28 08:02:56 25 4
gpt4 key购买 nike

我想在应用终止时获取用户位置更新。

我尝试过的:在 AppDelegate 中:

var locationManger: CLLocationManager!

在 applicationDidFinishLaunching 中

setupLocationManager()

还有在 AppDelegate 中:

@nonobjc func applicationWillTerminate(application: UIApplication) {
locationManger.startMonitoringSignificantLocationChanges()
}
func setupLocationManager(){
locationManger = CLLocationManager()
locationManger.delegate = self
locationManger.requestAlwaysAuthorization()
locationManger.desiredAccuracy = kCLLocationAccuracyHundredMeters
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if UIApplication.shared.applicationState == .inactive{
let notification = UNMutableNotificationContent()
notification.title = "Location Update"
notification.body = "updated in background"

let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "locationUpdate", content: notification, trigger: notificationTrigger)

UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}

}

但是我没有收到推送通知...有任何想法吗?引用这篇文章:IOS Getting location updates when app terminated without using significantChange应该可以的

最佳答案

您是否尝试过在此处启用后台获取? enter image description here

关于ios - 应用程序终止时的位置更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46111229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com