가능합니다. AppDelegate didFinishLaunchingWithOptions에서 알림 (백그라운드에서 수신 된 APN)에서 시작되었는지 확인한 다음 위치 서비스를 시작합니다. 위치를 받으면 백엔드로 보내고 위치 서비스를 종료하십시오. 일반에서 시스템이 위치를 반환하기 전에 약간의 지연이있을 것이라는 점에 유의하십시오. 그러나 앱이 다시 잠자기 전에 경과 한 시간은 시간에 이루어져야합니다. 필요한 경우 배경을 추가로 얻는 방법이 몇 가지 있습니다 (예 : ).
// untested code, ignores all of the boilerplate Location Services Authorization code and request user permission to Location services
var locationManager: CLLocationManager?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Check if launched from notification (received APN while in background)
if let notification = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [String: AnyObject] {
let aps = notification["aps"] as! [String: AnyObject]
print("received background apn, aps: \(aps)")
locationManager = CLLocationManager()
locationManager!.delegate = self
locationManager!.startUpdatingLocation() // this is what starts the location services query
}
...
return true
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
// here is where you would send location to your backend
// shut down location services:
locationManager?.stopUpdatingLocation()
locationManager?.delegate = nil
locationManager = nil
}
해결책은 백그라운드에서 위치 데이터를 계속 가져 와서 알림을 사용하는 것입니다. 백그라운드에서 위치를 계속 가져 오려면 http://stackoverflow.com/a/24666487/548403 –