Repository navigation
Conversation
Proxying a delegate that handles a selector via forwardingTargetForSelector: instead of implementing it caused the callback to be dropped silently. createSubclassWithObject: records the original implementation with class_getInstanceMethod(realClass, sel), which is NULL for such a delegate. Adding the donor method then makes message lookup succeed, so the runtime no longer consults the forwarding target, and each donor's trailing `if (realIMP)` is false. The message is neither delivered nor diagnosed. This is the shape of the delegate SwiftUI installs for UIApplicationDelegateAdaptor: SwiftUI.AppDelegate implements only a handful of selectors -- didFinishLaunchingWithOptions:, configurationForConnecting:options:, handleEventsForBackgroundURLSession:, respondsToSelector: and forwardingTargetForSelector: -- and forwards the rest to the app's own delegate. An app using that adaptor together with FirebaseMessaging or FirebaseAuth therefore stops receiving the APNS callbacks on its own delegate, and any app using a GoogleUtilities-based SDK stops receiving continueUserActivity: and openURL:options:. Each donor now falls back to the forwarding target when the original implementation is NULL, so the behaviour is unchanged for delegates that implement the selector themselves.
daymxn
requested changes
Sep 28, 2026
Author
|
Hey @daymxn, thanks for the review. All suggestions applied. |
Forward through NSInvocation rather than by messaging the target directly, so that the APNS App Delegate selectors are not referenced as symbols. Referencing them directly triggers an Apple review warning about a missing Push Notification Entitlement even when the code never runs, which is why the surrounding code builds those selectors from strings. Adds tests for the value returned by a forwarded selector, for the completion handlers of application:handleEventsForBackgroundURLSession:completionHandler: and application:didReceiveRemoteNotification:fetchCompletionHandler:, and for a forwarding delegate whose target does not implement the selector at all. Adds the changelog entry.
tetek
force-pushed
the
fix/forwarding-target-app-delegate
branch
from
September 30, 2026 07:22
5a805af to
63f9c4f
Compare
Member
|
@tetek Based on the CI run, it looks the change doesn't build on macOS. Please address. |
Fixes the macOS build: openURL:options:, handleEventsForBackgroundURLSession: and the fetchCompletionHandler: variant aren't part of NSApplicationDelegate.
tetek
force-pushed
the
fix/forwarding-target-app-delegate
branch
from
October 5, 2026 14:27
3de1621 to
bb9ec99
Compare
Member
|
Thanks @tetek - I asked an agent to take a look and it came back with the following:
|
- Enter the callback group and call forwardSelector: once, leaving the group if nothing was forwarded, so the system completion handler always runs. - Guard stored completion handlers against nil in tests and assert the forwarded fetch result. - Add a test merging an interceptor's fetch result with a forwarding delegate. - Wrap the CHANGELOG entry at 80 columns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey,
I've been tracking down an unwanted behaviour in a SwiftUI app using Firebase.
I set my AppDelegate with
UIApplicationDelegateAdaptor.After adding Firebase I stopped receiving:
after calling
UIApplication.shared.registerForRemoteNotifications().It turns out
UIApplicationDelegateAdaptorinstalls SwiftUI's ownSwiftUI.AppDelegateas theapplication delegate, which implements only a handful of selectors itself and forwards the rest to
the app's delegate via
forwardingTargetForSelector:.With the App Delegate Proxy active (the default),
createSubclassWithObject:records the originalimplementation using
class_getInstanceMethod(realClass, sel), which isNULLfor a forwardedselector. Adding the donor method then makes message lookup succeed, so the runtime no longer
consults the forwarding target, and each donor's trailing
if (realIMP)is false — the callbackreaches the interceptors but is never delivered to the app's delegate, with no diagnostic.
This isn't limited to APNS:
application:continueUserActivity:restorationHandler:andapplication:openURL:options:are lost the same way for any app using the adaptor together with aGoogleUtilities-based SDK.
This PR makes each donor fall back to the forwarding target when the original implementation is
NULL, leaving behaviour unchanged for delegates that implement the selector themselves.Seven tests cover this: forwarded APNS callbacks,
continueUserActivity, interceptors still beingnotified, return values, completion handlers, merging the fetch result with interceptors, and
a forwarding target that doesn't implement the selector.
Related: firebase/firebase-ios-sdk#13566, firebase/firebase-ios-sdk#14751,
firebase/firebase-ios-sdk#10417