17
17
#include " app/src/util_ios.h"
18
18
19
19
#include " app/src/assert.h"
20
- #include " app/src/include/firebase/internal/common.h"
21
- #include " app/src/log.h"
22
20
23
21
#include < assert.h>
24
22
#include < stdlib.h>
29
27
30
28
static IMP g_original_setDelegate_imp = NULL ;
31
29
static Class g_app_delegate_class = nil ;
32
- static void (^g_pending_app_delegate_block)(Class ) = nil; // New
33
-
34
- #include " app/src/log.h" // For LogDebug
30
+ static void (^g_pending_app_delegate_block)(Class ) = nil;
35
31
36
32
// Swizzled implementation of setDelegate:
37
33
static void Firebase_setDelegate (id self, SEL _cmd, id <UIApplicationDelegate> delegate) {
38
34
if (delegate) {
39
35
g_app_delegate_class = [delegate class ];
40
- firebase::LogDebug ( " Firebase: UIApplication setDelegate: called with class %s (Swizzled)" ,
36
+ NSLog ( @ " Firebase: UIApplication setDelegate: called with class %s (Swizzled)" ,
41
37
class_getName (g_app_delegate_class));
42
38
} else {
43
39
g_app_delegate_class = nil ;
44
- firebase::LogDebug ( " Firebase: UIApplication setDelegate: called with nil delegate (Swizzled)" );
40
+ NSLog ( @ " Firebase: UIApplication setDelegate: called with nil delegate (Swizzled)" );
45
41
}
46
42
47
- // New part to add:
48
43
if (g_pending_app_delegate_block && g_app_delegate_class) {
49
- firebase::LogDebug ( " Firebase: Firebase_setDelegate executing pending block with delegate class: %s." ,
44
+ NSLog ( @ " Firebase: Firebase_setDelegate executing pending block with delegate class: %s ." ,
50
45
class_getName (g_app_delegate_class));
51
46
g_pending_app_delegate_block (g_app_delegate_class);
52
47
g_pending_app_delegate_block = nil ; // Clear the block after execution (ARC handles release)
53
48
} else if (g_pending_app_delegate_block && !g_app_delegate_class) {
54
49
// This case: setDelegate was called with nil, but a block was pending.
55
50
// The pending block expects a Class. We don't have one.
56
51
// So, we should clear the pending block as it can no longer be satisfied.
57
- firebase::LogDebug ( " Firebase: Firebase_setDelegate called with nil delegate, clearing pending block as it cannot be executed." );
52
+ NSLog ( @ " Firebase: Firebase_setDelegate called with nil delegate, clearing pending block as it cannot be executed." );
58
53
g_pending_app_delegate_block = nil ;
59
54
}
60
55
61
56
if (g_original_setDelegate_imp) {
62
57
((void (*)(id , SEL , id <UIApplicationDelegate>))g_original_setDelegate_imp)(self, _cmd, delegate);
63
58
} else {
64
- firebase::LogError ( " Firebase: Original setDelegate: IMP not found, cannot call original method." );
59
+ NSLog ( @ " Firebase Error : Original setDelegate: IMP not found, cannot call original method." );
65
60
}
66
61
}
67
62
@@ -75,16 +70,16 @@ + (void)load {
75
70
Method originalMethod = class_getInstanceMethod (uiApplicationClass, originalSelector);
76
71
77
72
if (!originalMethod) {
78
- firebase::LogError ( " Firebase: Original [UIApplication setDelegate:] method not found for swizzling." );
73
+ NSLog ( @ " Firebase Error : Original [UIApplication setDelegate:] method not found for swizzling." );
79
74
return ;
80
75
}
81
76
82
77
IMP previousImp = method_setImplementation (originalMethod, (IMP )Firebase_setDelegate);
83
78
if (previousImp) {
84
79
g_original_setDelegate_imp = previousImp;
85
- firebase::LogDebug ( " Firebase: Successfully swizzled [UIApplication setDelegate:] and stored original IMP." );
80
+ NSLog ( @ " Firebase: Successfully swizzled [UIApplication setDelegate:] and stored original IMP." );
86
81
} else {
87
- firebase::LogError ( " Firebase: Swizzled [UIApplication setDelegate:], but original IMP was NULL (or method_setImplementation failed)." );
82
+ NSLog ( @ " Firebase Error : Swizzled [UIApplication setDelegate:], but original IMP was NULL (or method_setImplementation failed)." );
88
83
}
89
84
});
90
85
}
@@ -145,15 +140,15 @@ - (BOOL)application:(UIApplication *)application
145
140
146
141
void ForEachAppDelegateClass (void (^block)(Class )) {
147
142
if (g_app_delegate_class) {
148
- firebase::LogDebug ( " Firebase: ForEachAppDelegateClass executing with stored delegate class: %s." ,
143
+ NSLog ( @ " Firebase: ForEachAppDelegateClass executing with stored delegate class: %s ." ,
149
144
class_getName (g_app_delegate_class));
150
145
block (g_app_delegate_class);
151
146
// Clear any pending block as we've now executed with a known delegate.
152
147
if (g_pending_app_delegate_block) {
153
148
g_pending_app_delegate_block = nil ; // ARC handles release
154
149
}
155
150
} else {
156
- firebase::LogDebug ( " Firebase: ForEachAppDelegateClass - delegate class not yet known. Saving block for later execution." );
151
+ NSLog ( @ " Firebase: ForEachAppDelegateClass - delegate class not yet known. Saving block for later execution." );
157
152
// If a block is already pending, the new one replaces it. ARC handles the old one.
158
153
// Make sure to copy the block to move it to the heap.
159
154
g_pending_app_delegate_block = [block copy ];
0 commit comments