Skip to content

Commit e602426

Browse files
fix(auth,ios): allow firebase_auth to compile under APPLICATION_EXTENSION_API_ONLY
Fixes #18232. Wraps the four call sites in FLTFirebaseAuthPlugin.m that reference APIs unavailable to app extensions: - -[FlutterPluginRegistrar addApplicationDelegate:] in +registerWithRegistrar: (line 156) - +[UIApplication sharedApplication].connectedScenes (lines 904, 914) - +[[UIApplication sharedApplication] keyWindow] fallback (line 926) The first is gated with #if !TARGET_OS_EXTENSION. The presentationAnchorForAuthorizationController: method already had TARGET_OS_OSX branching; this adds an extension branch that returns nil. Sign-in flows that require a presentation anchor cannot run from an extension context, so this method is not expected to be invoked there. Pre-extension behaviour is unchanged on iOS and macOS host targets.
1 parent 7d1a8b1 commit e602426

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/FLTFirebaseAuthPlugin.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,13 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
153153
[registrar addMethodCallDelegate:instance channel:channel];
154154

155155
[registrar publish:instance];
156+
#if !TARGET_OS_EXTENSION
157+
// -[FlutterPluginRegistrar addApplicationDelegate:] is unavailable when
158+
// building for an app extension target (APPLICATION_EXTENSION_API_ONLY=YES).
159+
// The application-delegate callbacks below (openURL etc.) are never
160+
// exercised in extensions because sign-in flows cannot run from there.
156161
[registrar addApplicationDelegate:instance];
162+
#endif
157163
#if !TARGET_OS_OSX
158164
if (@available(iOS 13.0, *)) {
159165
if ([registrar respondsToSelector:@selector(addSceneDelegate:)]) {
@@ -897,7 +903,7 @@ - (nonnull ASPresentationAnchor)presentationAnchorForAuthorizationController:
897903
(nonnull ASAuthorizationController *)controller API_AVAILABLE(macos(10.15), ios(13.0)) {
898904
#if TARGET_OS_OSX
899905
return [[NSApplication sharedApplication] keyWindow];
900-
#else
906+
#elif !TARGET_OS_EXTENSION
901907
// UIApplication.keyWindow is deprecated in iOS 13+ with UIScene lifecycle.
902908
// Walk the connected scenes to find the foreground active window.
903909
if (@available(iOS 15.0, *)) {
@@ -924,6 +930,12 @@ - (nonnull ASPresentationAnchor)presentationAnchorForAuthorizationController:
924930
}
925931
}
926932
return [[UIApplication sharedApplication] keyWindow];
933+
#else
934+
// App-extension build: +[UIApplication sharedApplication] is unavailable.
935+
// Sign-in flows that require a presentation anchor cannot run from an
936+
// extension — the host app is the only context that can present them —
937+
// so this method is not expected to be invoked here.
938+
return (ASPresentationAnchor)nil;
927939
#endif
928940
}
929941

0 commit comments

Comments
 (0)