@@ -58,8 +58,7 @@ - (void)application:(UIApplication *)application
58
58
}
59
59
- (void )application : (UIApplication *)application
60
60
didReceiveRemoteNotification : (NSDictionary *)userInfo
61
- fetchCompletionHandler :
62
- (void (^)(UIBackgroundFetchResult result))handler {
61
+ fetchCompletionHandler : (void (^)(UIBackgroundFetchResult result))handler {
63
62
}
64
63
#if defined(__IPHONE_12_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0
65
64
- (BOOL )application : (UIApplication *)application
@@ -74,7 +73,7 @@ - (BOOL)application:(UIApplication *)application
74
73
restorationHandler : (void (^)(NSArray *))restorationHandler {
75
74
return NO ;
76
75
}
77
- #endif // defined(__IPHONE_12_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0
76
+ #endif // defined(__IPHONE_12_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0
78
77
@end
79
78
80
79
namespace firebase {
@@ -102,17 +101,19 @@ void ForEachAppDelegateClass(void (^block)(Class)) {
102
101
}
103
102
}
104
103
if (!blacklisted) {
105
- ::firebase::LogDebug (" Firebase: Found UIApplicationDelegate class %s" ,
106
- class_name);
104
+ if (GetLogLevel () <= kLogLevelDebug ) {
105
+ // Call NSLog directly because we may be in a +load method,
106
+ // and C++ classes may not be constructed yet.
107
+ NSLog (@" Firebase: Found UIApplicationDelegate class %s " , class_name);
108
+ }
107
109
block (clazz);
108
110
}
109
111
}
110
112
}
111
113
free (classes);
112
114
}
113
115
114
- NSDictionary *StringMapToNSDictionary (
115
- const std::map<std::string, std::string> &string_map) {
116
+ NSDictionary *StringMapToNSDictionary (const std::map<std::string, std::string> &string_map) {
116
117
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc ] init ];
117
118
for (auto &kv : string_map) {
118
119
dictionary[[NSString stringWithUTF8String: kv.first.c_str ()]] =
@@ -121,8 +122,7 @@ void ForEachAppDelegateClass(void (^block)(Class)) {
121
122
return dictionary;
122
123
}
123
124
124
- NSDictionary *CharArrayMapToNSDictionary (
125
- const std::map<const char *, const char *> &string_map) {
125
+ NSDictionary *CharArrayMapToNSDictionary (const std::map<const char *, const char *> &string_map) {
126
126
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc ] init ];
127
127
for (auto &kv : string_map) {
128
128
dictionary[[NSString stringWithUTF8String: kv.first]] =
@@ -143,17 +143,14 @@ void ForEachAppDelegateClass(void (^block)(Class)) {
143
143
return std::string (static_cast <const char *>(data.bytes ), data.length );
144
144
}
145
145
146
- NSString *StringToNSString (const std::string &str) {
147
- return CStringToNSString (str.c_str ());
148
- }
146
+ NSString *StringToNSString (const std::string &str) { return CStringToNSString (str.c_str ()); }
149
147
150
148
NSString *CStringToNSString (const char *c_str) {
151
149
return [NSString stringWithCString: c_str encoding: NSUTF8StringEncoding];
152
150
}
153
151
154
152
std::string NSStringToString (NSString *str) {
155
- return str ? std::string ([str cStringUsingEncoding: NSUTF8StringEncoding]) :
156
- std::string ();
153
+ return str ? std::string ([str cStringUsingEncoding: NSUTF8StringEncoding]) : std::string ();
157
154
}
158
155
159
156
NSMutableArray *StringVectorToNSMutableArray (const std::vector<std::string> &vector) {
@@ -164,41 +161,37 @@ void ForEachAppDelegateClass(void (^block)(Class)) {
164
161
return array;
165
162
}
166
163
167
- NSMutableArray * StdVectorToNSMutableArray (const std::vector<Variant>& vector) {
168
- NSMutableArray * array =
169
- [[NSMutableArray alloc ] initWithCapacity: vector.size ()];
170
- for (auto & variant : vector) {
164
+ NSMutableArray *StdVectorToNSMutableArray (const std::vector<Variant> &vector) {
165
+ NSMutableArray *array = [[NSMutableArray alloc ] initWithCapacity: vector.size ()];
166
+ for (auto &variant : vector) {
171
167
[array addObject: VariantToId (variant)];
172
168
}
173
169
return array;
174
170
}
175
171
176
- NSMutableDictionary * StdMapToNSMutableDictionary (
177
- const std::map<Variant, Variant>& map) {
178
- NSMutableDictionary * dictionary =
179
- [[NSMutableDictionary alloc ] initWithCapacity: map.size ()];
180
- for (auto & pair : map) {
181
- [dictionary setObject: VariantToId (pair.second)
182
- forKey: VariantToId (pair.first)];
172
+ NSMutableDictionary *StdMapToNSMutableDictionary (const std::map<Variant, Variant> &map) {
173
+ NSMutableDictionary *dictionary = [[NSMutableDictionary alloc ] initWithCapacity: map.size ()];
174
+ for (auto &pair : map) {
175
+ [dictionary setObject: VariantToId (pair.second) forKey: VariantToId (pair.first)];
183
176
}
184
177
return dictionary;
185
178
}
186
179
187
- void NSArrayToStdVector (NSArray *array, std::vector<Variant>* vector) {
180
+ void NSArrayToStdVector (NSArray *array, std::vector<Variant> * vector) {
188
181
vector->reserve (array.count );
189
182
for (id object in array) {
190
183
vector->push_back (IdToVariant (object));
191
184
}
192
185
}
193
186
194
- void NSDictionaryToStdMap (NSDictionary *dictionary, std::map<Variant, Variant>* map) {
187
+ void NSDictionaryToStdMap (NSDictionary *dictionary, std::map<Variant, Variant> * map) {
195
188
for (id key in dictionary) {
196
189
id value = [dictionary objectForKey: key];
197
190
map->insert (std::make_pair (IdToVariant (key), IdToVariant (value)));
198
191
}
199
192
}
200
193
201
- id VariantToId (const Variant& variant) {
194
+ id VariantToId (const Variant & variant) {
202
195
switch (variant.type ()) {
203
196
case Variant::kTypeNull : {
204
197
return [NSNull null ];
@@ -231,22 +224,18 @@ id VariantToId(const Variant& variant) {
231
224
232
225
static bool IdIsBoolean (id value) {
233
226
if ([value isKindOfClass: [NSNumber class ]]) {
234
- const char * type = [value objCType ];
235
- return strcmp (type, @encode (BOOL )) == 0 ||
236
- strcmp (type, @encode (signed char )) == 0 ;
227
+ const char *type = [value objCType ];
228
+ return strcmp (type, @encode (BOOL )) == 0 || strcmp (type, @encode (signed char )) == 0 ;
237
229
}
238
230
return false ;
239
231
}
240
232
241
233
static bool IdIsInteger (id value) {
242
234
if ([value isKindOfClass: [NSNumber class ]]) {
243
- const char * type = [value objCType ];
244
- return strcmp (type, @encode (int )) == 0 ||
245
- strcmp (type, @encode (short )) == 0 ||
246
- strcmp (type, @encode (long )) == 0 ||
247
- strcmp (type, @encode (long long )) == 0 ||
248
- strcmp (type, @encode (unsigned char )) == 0 ||
249
- strcmp (type, @encode (unsigned int )) == 0 ||
235
+ const char *type = [value objCType ];
236
+ return strcmp (type, @encode (int )) == 0 || strcmp (type, @encode (short )) == 0 ||
237
+ strcmp (type, @encode (long )) == 0 || strcmp (type, @encode (long long )) == 0 ||
238
+ strcmp (type, @encode (unsigned char )) == 0 || strcmp (type, @encode (unsigned int )) == 0 ||
250
239
strcmp (type, @encode (unsigned short )) == 0 ||
251
240
strcmp (type, @encode (unsigned long )) == 0 ||
252
241
strcmp (type, @encode (unsigned long long )) == 0 ;
@@ -256,9 +245,8 @@ static bool IdIsInteger(id value) {
256
245
257
246
static bool IdIsFloatingPoint (id value) {
258
247
if ([value isKindOfClass: [NSNumber class ]]) {
259
- const char * type = [value objCType ];
260
- return strcmp (type, @encode (float )) == 0 ||
261
- strcmp (type, @encode (double )) == 0 ;
248
+ const char *type = [value objCType ];
249
+ return strcmp (type, @encode (float )) == 0 || strcmp (type, @encode (double )) == 0 ;
262
250
}
263
251
return false ;
264
252
}
@@ -307,15 +295,13 @@ void DispatchAsyncSafeMainQueue(void (^block)(void)) {
307
295
}
308
296
}
309
297
310
- void RunOnMainThread (void (*function_ptr)(void *function_data),
311
- void *function_data) {
298
+ void RunOnMainThread (void (*function_ptr)(void *function_data), void *function_data) {
312
299
dispatch_async (dispatch_get_main_queue (), ^{
313
300
function_ptr (function_data);
314
301
});
315
302
}
316
303
317
- void RunOnBackgroundThread (void (*function_ptr)(void *function_data),
318
- void *function_data) {
304
+ void RunOnBackgroundThread (void (*function_ptr)(void *function_data), void *function_data) {
319
305
dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
320
306
function_ptr (function_data);
321
307
});
@@ -350,12 +336,14 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data),
350
336
351
337
// Get the type encoding of the selector from a type_encoding_class (which is a class which
352
338
// implements a stub for the method).
353
- const char *type_encoding = method_getTypeEncoding (
354
- class_getInstanceMethod (type_encoding_class, name));
339
+ const char *type_encoding =
340
+ method_getTypeEncoding ( class_getInstanceMethod (type_encoding_class, name));
355
341
FIREBASE_ASSERT (type_encoding);
356
342
357
343
NSString *new_method_name_nsstring = nil ;
358
- ::firebase::LogDebug (" Registering method for %s selector %s" , class_name, selector_name);
344
+ if (GetLogLevel () <= kLogLevelDebug ) {
345
+ NSLog (@" Registering method for %s selector %s " , class_name, selector_name);
346
+ }
359
347
if (original_method_implementation) {
360
348
// Try adding a method with randomized prefix on the name.
361
349
int retry = kRandomNameGenerationRetries ;
@@ -370,27 +358,32 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data),
370
358
}
371
359
const char *new_method_name = new_method_name_nsstring.UTF8String ;
372
360
if (retry == 0 ) {
373
- LogError ( " Failed to add method %s on class %s as the %s method already exists on the class. "
374
- " To resolve this issue, change the name of the method %s on the class %s." ,
375
- new_method_name, class_name, new_method_name, new_method_name, class_name);
361
+ NSLog ( @ " Failed to add method %s on class %s as the %s method already exists on the class. To "
362
+ @" resolve this issue, change the name of the method %s on the class %s ." ,
363
+ new_method_name, class_name, new_method_name, new_method_name, class_name);
376
364
return ;
377
365
}
378
366
method_setImplementation (method, imp);
379
367
// Save the selector name that points at the original method implementation.
380
368
SetMethod (name, new_method_name_nsstring);
381
- ::firebase::LogDebug (" Registered method for %s selector %s (original method %s 0x%08x)" ,
382
- class_name, selector_name, new_method_name,
383
- static_cast <int >(reinterpret_cast <intptr_t >(
384
- original_method_implementation)));
369
+ if (GetLogLevel () <= kLogLevelDebug ) {
370
+ NSLog (@" Registered method for %s selector %s (original method %s 0x%08x )" , class_name,
371
+ selector_name, new_method_name,
372
+ static_cast <int >(reinterpret_cast <intptr_t >(original_method_implementation)));
373
+ }
385
374
} else if (add_method) {
386
- ::firebase::LogDebug (" Adding method for %s selector %s" , class_name, selector_name);
375
+ if (GetLogLevel () <= kLogLevelDebug ) {
376
+ NSLog (@" Adding method for %s selector %s " , class_name, selector_name);
377
+ }
387
378
// The class doesn't implement the selector so simply install our method implementation.
388
379
if (!class_addMethod (clazz, name, imp, type_encoding)) {
389
- LogError ( " Failed to add new method %s on class %s." , selector_name, class_name);
380
+ NSLog ( @ " Failed to add new method %s on class %s ." , selector_name, class_name);
390
381
}
391
382
} else {
392
- ::firebase::LogDebug (" Method implementation for %s selector %s not found, ignoring." ,
393
- class_name, selector_name);
383
+ if (GetLogLevel () <= kLogLevelDebug ) {
384
+ NSLog (@" Method implementation for %s selector %s not found, ignoring." , class_name,
385
+ selector_name);
386
+ }
394
387
}
395
388
}
396
389
@@ -420,19 +413,19 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data),
420
413
const char *selector_implementation_name = selector_implementation_name_nsstring.UTF8String ;
421
414
SEL selector_implementation = NSSelectorFromString (selector_implementation_name_nsstring);
422
415
search_class = clazz;
423
- for ( ; search_class; search_class = class_getSuperclass (search_class)) {
416
+ for (; search_class; search_class = class_getSuperclass (search_class)) {
424
417
const char *search_class_name = class_getName (search_class);
425
- firebase::LogDebug (" Searching for selector %s (%s) on class %s" ,
426
- selector_name, selector_implementation_name, search_class_name);
418
+ firebase::LogDebug (" Searching for selector %s (%s) on class %s" , selector_name,
419
+ selector_implementation_name, search_class_name);
427
420
Method method = class_getInstanceMethod (search_class, selector_implementation);
428
421
method_implementation = method ? method_getImplementation (method) : nil ;
429
422
if (method_implementation) break ;
430
423
}
431
424
if (method_implementation) break ;
432
425
}
433
426
if (!method_implementation) {
434
- firebase::LogDebug (" Class %s does not respond to selector %s (%s)" , class_name,
435
- selector_name, selector_implementation_name_nsstring.UTF8String );
427
+ firebase::LogDebug (" Class %s does not respond to selector %s (%s)" , class_name, selector_name,
428
+ selector_implementation_name_nsstring.UTF8String );
436
429
return nil ;
437
430
}
438
431
firebase::LogDebug (" Found %s (%s, 0x%08x) on class %s (%s)" , selector_name,
@@ -472,8 +465,8 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data),
472
465
while (retry--) {
473
466
// Cache the old method implementation in a new method so that we can lookup the original
474
467
// implementation from the instance of the class.
475
- NSString *random_selector_name = [[ NSString alloc ] initWithFormat: @" FIRA %x %@ " , arc4random (),
476
- selector_name];
468
+ NSString *random_selector_name =
469
+ [[ NSString alloc ] initWithFormat: @" FIRA %x %@ " , arc4random (), selector_name];
477
470
if (!implementation_selector_names[random_selector_name]) {
478
471
return random_selector_name;
479
472
}
0 commit comments