You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature: Allow specifying AppDelegate via Info.plist for RunOnAppDelegateClasses
Currently, `firebase::util::RunOnAppDelegateClasses` on iOS automatically
swizzles `[UIApplication setDelegate:]` to capture and act on any class
set as the application delegate.
This change introduces an optional feature where developers can specify their
app's main AppDelegate class name directly in the `Info.plist` file using
the key `FirebaseAppDelegateClassName`.
If this key is present and provides a valid class name:
- `RunOnAppDelegateClasses` will only execute blocks for this specified class.
- `[UIApplication setDelegate:]` will NOT be swizzled by Firebase.
If the key is not present, is invalid, or the specified class is not found,
Firebase will fall back to the original behavior of swizzling
`[UIApplication setDelegate:]`.
This provides developers more control over Firebase's interaction with the
AppDelegate, especially in scenarios where swizzling might be undesirable or
needs to be more targeted.
Detailed logging has been added to trace the behavior in both modes.
A manual testing plan has been outlined to cover various scenarios.
NSLog(@"Firebase: %@ is now the only 'seen' delegate class.", appDelegateClassName);
194
+
return; // IMPORTANT: Do not proceed to swizzle setDelegate:
195
+
} else {
196
+
NSLog(@"Firebase Error: Info.plist key '%@' provided class name '%@', but this class was not found. Proceeding with default setDelegate: swizzling.", kFirebaseAppDelegateClassNameKey, appDelegateClassName);
197
+
}
198
+
} else {
199
+
if (appDelegateClassName) { // Key exists but is empty or not a string
200
+
NSLog(@"Firebase Warning: Info.plist key '%@' is present but invalid (empty or not a string: %@). Proceeding with default setDelegate: swizzling.", kFirebaseAppDelegateClassNameKey, appDelegateClassName);
201
+
} else { // Key does not exist
202
+
NSLog(@"Firebase: Info.plist key '%@' not found. Proceeding with default setDelegate: swizzling.", kFirebaseAppDelegateClassNameKey);
203
+
}
204
+
}
205
+
206
+
// Original swizzling logic if the Info.plist key is not used or class not found
NSLog(@"Firebase: Successfully swizzled [UIApplication setDelegate:] and stored original IMP.");
181
220
} else {
182
-
// This would be unusual - method_setImplementation replacing a NULL IMP,
183
-
// or method_setImplementation itself failed (though it doesn't typically return NULL on failure,
184
-
// it might return the new IMP or the old one depending on versions/runtime).
185
-
// More robustly, g_original_setDelegate_imp should be checked before use.
186
-
// For now, this logging indicates if previousImp was unexpectedly nil.
187
221
NSLog(@"Firebase Error: Swizzled [UIApplication setDelegate:], but original IMP was NULL (or method_setImplementation failed to return the previous IMP).");
NSLog(@"Firebase: RunOnAppDelegateClasses - added block to pending list (total pending: %d). This block will run on future new delegate classes.", g_pending_block_count);
215
-
} else {
216
-
NSLog(@"Firebase Error: RunOnAppDelegateClasses - pending block queue is full (max %d). Cannot add new block for future execution. Discarding block.", MAX_PENDING_APP_DELEGATE_BLOCKS);
295
+
// Always try to queue the block for any future new delegate classes in swizzle mode.
296
+
if (g_pending_block_count < MAX_PENDING_APP_DELEGATE_BLOCKS) {
NSLog(@"Firebase: RunOnAppDelegateClasses (Swizzle Mode) - added block to pending list (total pending: %d). This block will run on future new delegate classes.", g_pending_block_count);
300
+
} else {
301
+
NSLog(@"Firebase Error: RunOnAppDelegateClasses (Swizzle Mode) - pending block queue is full (max %d). Cannot add new block for future execution. Discarding block.", MAX_PENDING_APP_DELEGATE_BLOCKS);
0 commit comments