Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2020 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#import "FirebasePerformance/Sources/Common/FPRDiagnostics.h"
16
#import "FirebasePerformance/Sources/Common/FPRDiagnostics_Private.h"
17
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
18
 
19
void __FPRAssert(id object, BOOL condition, const char *func) {
20
  static BOOL diagnosticsEnabled = NO;
21
  static dispatch_once_t onceToken;
22
  NSDictionary<NSString *, NSString *> *environment = [NSProcessInfo processInfo].environment;
23
  // Enable diagnostics when in test environment
24
  if (environment[@"XCTestConfigurationFilePath"] != nil) {
25
    diagnosticsEnabled = [FPRDiagnostics isEnabled];
26
  } else {
27
    dispatch_once(&onceToken, ^{
28
      diagnosticsEnabled = [FPRDiagnostics isEnabled];
29
    });
30
  }
31
 
32
  if (__builtin_expect(!condition && diagnosticsEnabled, NO)) {
33
    FPRLogError(kFPRDiagnosticFailure, @"Failure in %s, information follows:", func);
34
    FPRLogNotice(kFPRDiagnosticLog, @"Stack for failure in %s:\n%@", func,
35
                 [NSThread callStackSymbols]);
36
    if ([[object class] respondsToSelector:@selector(emitDiagnostics)]) {
37
      [[object class] performSelector:@selector(emitDiagnostics) withObject:nil];
38
    }
39
    if ([object respondsToSelector:@selector(emitDiagnostics)]) {
40
      [object performSelector:@selector(emitDiagnostics) withObject:nil];
41
    }
42
    FPRLogNotice(kFPRDiagnosticLog, @"End of diagnostics for %s failure.", func);
43
  }
44
}
45
 
46
@implementation FPRDiagnostics
47
 
48
static FPRConfigurations *_configuration;
49
 
50
+ (void)initialize {
51
  _configuration = [FPRConfigurations sharedInstance];
52
}
53
 
54
+ (FPRConfigurations *)configuration {
55
  return _configuration;
56
}
57
 
58
+ (void)setConfiguration:(FPRConfigurations *)config {
59
  _configuration = config;
60
}
61
 
62
+ (BOOL)isEnabled {
63
  // Check a soft-linked FIRCore class to see if this is running in the app store.
64
  Class FIRAppEnvironmentUtil = NSClassFromString(@"FIRAppEnvironmentUtil");
65
  SEL isFromAppStore = NSSelectorFromString(@"isFromAppStore");
66
#pragma clang diagnostic push
67
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
68
  if (FIRAppEnvironmentUtil && [FIRAppEnvironmentUtil respondsToSelector:isFromAppStore] &&
69
      [FIRAppEnvironmentUtil performSelector:isFromAppStore]) {
70
    return NO;
71
  }
72
#pragma clang diagnostic pop
73
  BOOL enabled = [FPRDiagnostics.configuration diagnosticsEnabled];
74
  if (enabled) {
75
    static dispatch_once_t onceToken;
76
    dispatch_once(&onceToken, ^{
77
      FPRLogNotice(kFPRDiagnosticInfo, @"Firebase Performance Diagnostics have been enabled!");
78
    });
79
  }
80
  return enabled;
81
}
82
 
83
@end