diff --git a/resources/ios/BSHArrivalMonitor.swift b/resources/ios/BSHArrivalMonitor.swift index d5d8590..091aabf 100644 --- a/resources/ios/BSHArrivalMonitor.swift +++ b/resources/ios/BSHArrivalMonitor.swift @@ -1,11 +1,29 @@ import Foundation import CoreLocation +import UIKit /// Every launch hook of the plugin, run by `ios.init_function`. enum BSHLaunch { + private static var launchObserver: NSObjectProtocol? + static func install() { BSHNotificationCenter.install() - BSHArrivalMonitor.install() + + // `init_function` runs in the SwiftUI `App.init`, before the app has finished + // launching: a location manager started there deadlocks the CoreMotion thread + // that ARKit needs, so tracking never initialises. + launchObserver = NotificationCenter.default.addObserver( + forName: UIApplication.didFinishLaunchingNotification, + object: nil, + queue: .main + ) { _ in + if let observer = launchObserver { + NotificationCenter.default.removeObserver(observer) + launchObserver = nil + } + + BSHArrivalMonitor.install() + } } }