Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove calls to LogInfo, LogError, LogDebug during obj-c +load. #706

Merged
merged 4 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions app/src/util_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ void ForEachAppDelegateClass(void (^block)(Class)) {
}
}
if (!blacklisted) {
::firebase::LogDebug("Firebase: Found UIApplicationDelegate class %s",
class_name);
if (GetLogLevel() <= kLogLevelDebug) {
// Call NSLog directly because we may be in a +load method,
// and C++ classes may not be constructed yet.
NSLog(@"Firebase: Found UIApplicationDelegate class %s",
class_name);
}
block(clazz);
}
}
Expand Down Expand Up @@ -355,7 +359,9 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data),
FIREBASE_ASSERT(type_encoding);

NSString *new_method_name_nsstring = nil;
::firebase::LogDebug("Registering method for %s selector %s", class_name, selector_name);
if (GetLogLevel() <= kLogLevelDebug) {
NSLog(@"Registering method for %s selector %s", class_name, selector_name);
}
if (original_method_implementation) {
// Try adding a method with randomized prefix on the name.
int retry = kRandomNameGenerationRetries;
Expand All @@ -370,27 +376,32 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data),
}
const char *new_method_name = new_method_name_nsstring.UTF8String;
if (retry == 0) {
LogError("Failed to add method %s on class %s as the %s method already exists on the class. "
"To resolve this issue, change the name of the method %s on the class %s.",
NSLog(@"Failed to add method %s on class %s as the %s method already exists on the class. To resolve this issue, change the name of the method %s on the class %s.",
new_method_name, class_name, new_method_name, new_method_name, class_name);
return;
}
method_setImplementation(method, imp);
// Save the selector name that points at the original method implementation.
SetMethod(name, new_method_name_nsstring);
::firebase::LogDebug("Registered method for %s selector %s (original method %s 0x%08x)",
class_name, selector_name, new_method_name,
static_cast<int>(reinterpret_cast<intptr_t>(
original_method_implementation)));
if (GetLogLevel() <= kLogLevelDebug) {
NSLog(@"Registered method for %s selector %s (original method %s 0x%08x)",
class_name, selector_name, new_method_name,
static_cast<int>(reinterpret_cast<intptr_t>(
original_method_implementation)));
}
} else if (add_method) {
::firebase::LogDebug("Adding method for %s selector %s", class_name, selector_name);
if (GetLogLevel() <= kLogLevelDebug) {
NSLog(@"Adding method for %s selector %s", class_name, selector_name);
}
// The class doesn't implement the selector so simply install our method implementation.
if (!class_addMethod(clazz, name, imp, type_encoding)) {
LogError("Failed to add new method %s on class %s.", selector_name, class_name);
NSLog(@"Failed to add new method %s on class %s.", selector_name, class_name);
}
} else {
::firebase::LogDebug("Method implementation for %s selector %s not found, ignoring.",
class_name, selector_name);
if (GetLogLevel() <= kLogLevelDebug) {
NSLog(@"Method implementation for %s selector %s not found, ignoring.",
class_name, selector_name);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion messaging/src/ios/messaging.mm
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,8 @@ void SetTokenRegistrationOnInitEnabled(bool enable) {
// http://www.opensource.apple.com/source/objc4/objc4-274/runtime/objc-runtime.m)
@implementation UIApplication (FIRFCM)
+ (void)load {
::firebase::LogInfo("FCM: Loading UIApplication FIRFCM category");
// C++ constructors may not be called yet so call NSLog rather than LogInfo.
NSLog(@"FCM: Loading UIApplication FIRFCM category");
::firebase::util::ForEachAppDelegateClass(^(Class clazz) {
FirebaseMessagingHookAppDelegate(clazz);
});
Expand Down