Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2021 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 "Crashlytics/Crashlytics/Controllers/FIRCLSNotificationManager.h"
16
 
17
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
18
#import "Crashlytics/Crashlytics/Components/FIRCLSGlobals.h"
19
#import "Crashlytics/Crashlytics/Components/FIRCLSUserLogging.h"
20
 
21
#if TARGET_OS_IPHONE
22
#import <UIKit/UIKit.h>
23
#else
24
#import <AppKit/AppKit.h>
25
#endif
26
 
27
@implementation FIRCLSNotificationManager
28
 
29
- (void)registerNotificationListener {
30
  [self captureInitialNotificationStates];
31
 
32
#if TARGET_OS_IOS
33
  [[NSNotificationCenter defaultCenter] addObserver:self
34
                                           selector:@selector(willBecomeActive:)
35
                                               name:UIApplicationWillEnterForegroundNotification
36
                                             object:nil];
37
  [[NSNotificationCenter defaultCenter] addObserver:self
38
                                           selector:@selector(didBecomeInactive:)
39
                                               name:UIApplicationDidEnterBackgroundNotification
40
                                             object:nil];
41
  [[NSNotificationCenter defaultCenter] addObserver:self
42
                                           selector:@selector(didChangeOrientation:)
43
                                               name:UIDeviceOrientationDidChangeNotification
44
                                             object:nil];
45
 
46
#pragma clang diagnostic push
47
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
48
  [[NSNotificationCenter defaultCenter]
49
      addObserver:self
50
         selector:@selector(didChangeUIOrientation:)
51
             name:UIApplicationDidChangeStatusBarOrientationNotification
52
           object:nil];
53
#pragma clang diagnostic pop
54
 
55
#elif CLS_TARGET_OS_OSX
56
  [[NSNotificationCenter defaultCenter] addObserver:self
57
                                           selector:@selector(willBecomeActive:)
58
                                               name:@"NSApplicationWillBecomeActiveNotification"
59
                                             object:nil];
60
  [[NSNotificationCenter defaultCenter] addObserver:self
61
                                           selector:@selector(didBecomeInactive:)
62
                                               name:@"NSApplicationDidResignActiveNotification"
63
                                             object:nil];
64
#endif
65
}
66
 
67
- (void)captureInitialNotificationStates {
68
#if TARGET_OS_IOS
69
  UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
70
  UIInterfaceOrientation statusBarOrientation =
71
      [FIRCLSApplicationSharedInstance() statusBarOrientation];
72
#endif
73
 
74
  // It's nice to do this async, so we don't hold up the main thread while doing three
75
  // consecutive IOs here.
76
  dispatch_async(FIRCLSGetLoggingQueue(), ^{
77
    FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSInBackgroundKey, @"0");
78
#if TARGET_OS_IOS
79
    FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSDeviceOrientationKey,
80
                                           [@(orientation) description]);
81
    FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSUIOrientationKey,
82
                                           [@(statusBarOrientation) description]);
83
#endif
84
  });
85
}
86
 
87
- (void)willBecomeActive:(NSNotification *)notification {
88
  FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSInBackgroundKey, @NO);
89
}
90
 
91
- (void)didBecomeInactive:(NSNotification *)notification {
92
  FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSInBackgroundKey, @YES);
93
}
94
 
95
#if TARGET_OS_IOS
96
- (void)didChangeOrientation:(NSNotification *)notification {
97
  UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
98
 
99
  FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSDeviceOrientationKey, @(orientation));
100
}
101
 
102
- (void)didChangeUIOrientation:(NSNotification *)notification {
103
  UIInterfaceOrientation statusBarOrientation =
104
      [FIRCLSApplicationSharedInstance() statusBarOrientation];
105
 
106
  FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSUIOrientationKey, @(statusBarOrientation));
107
}
108
#endif
109
 
110
@end