From 789a6911436ee3571ba3a18ccea3b32928ecf0e2 Mon Sep 17 00:00:00 2001 From: Houssem Eddine BENABDALLAH Date: Thu, 19 Nov 2026 09:30:57 +0100 Subject: [PATCH] Start the arrival monitor once the app has finished launching --- resources/ios/BSHArrivalMonitor.swift | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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() + } } }