diff --git a/WatchApp Extension/ExtensionDelegate.swift b/WatchApp Extension/ExtensionDelegate.swift index dfd51a8510..ea1f3ac607 100644 --- a/WatchApp Extension/ExtensionDelegate.swift +++ b/WatchApp Extension/ExtensionDelegate.swift @@ -25,8 +25,11 @@ class ExtensionDelegate: NSObject, WKApplicationDelegate { private var observers: [NSKeyValueObservation] = [] private var notifications: [NSObjectProtocol] = [] + // WKApplication.shared().delegate is nil under the SwiftUI app lifecycle. + private static var instance: ExtensionDelegate! + static func shared() -> ExtensionDelegate { - return WKApplication.shared().extensionDelegate + return instance } let loopManager = LoopDataManager.shared @@ -42,6 +45,8 @@ class ExtensionDelegate: NSObject, WKApplicationDelegate { override init() { super.init() + Self.instance = self + let session = WCSession.default session.delegate = self @@ -422,10 +427,3 @@ extension ExtensionDelegate { WKApplication.shared().rootInterfaceController?.presentAlert(withTitle: error.localizedDescription, message: (error as NSError).localizedRecoverySuggestion ?? (error as NSError).localizedFailureReason, preferredStyle: .alert, actions: [WKAlertAction.dismissAction()]) } } - - -fileprivate extension WKApplication { - var extensionDelegate: ExtensionDelegate! { - return delegate as? ExtensionDelegate - } -}