Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@
7B14089824878F950035403D /* SentryCrashStackEntryMapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B14089724878F950035403D /* SentryCrashStackEntryMapper.m */; };
7B14089A248791660035403D /* SentryCrashStackEntryMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B140899248791660035403D /* SentryCrashStackEntryMapperTests.swift */; };
7B16FD022654F86B008177D3 /* SentrySysctlTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B16FD012654F86B008177D3 /* SentrySysctlTests.swift */; };
7B18DE4028D9F748004845C6 /* SentryNSNotificationCenterWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B18DE3F28D9F748004845C6 /* SentryNSNotificationCenterWrapper.h */; };
7B18DE4228D9F794004845C6 /* SentryNSNotificationCenterWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B18DE4128D9F794004845C6 /* SentryNSNotificationCenterWrapper.m */; };
7B18DE4428D9F8F6004845C6 /* TestNSNotificationCenterWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B18DE4328D9F8F6004845C6 /* TestNSNotificationCenterWrapper.swift */; };
7B18DE4A28DA0C8B004845C6 /* SentryNSNotificationCenterWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B18DE4928DA0C8B004845C6 /* SentryNSNotificationCenterWrapperTests.swift */; };
7B26BBFB24C0A66D00A79CCC /* SentrySdkInfoNilTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B26BBFA24C0A66D00A79CCC /* SentrySdkInfoNilTests.m */; };
7B2A70D827D5F080008B0D15 /* SentryANRTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B2A70D727D5F07F008B0D15 /* SentryANRTrackerTests.swift */; };
7B2A70DB27D607CF008B0D15 /* SentryThreadWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B2A70DA27D607CF008B0D15 /* SentryThreadWrapper.h */; };
Expand Down Expand Up @@ -998,6 +1002,10 @@
7B14089724878F950035403D /* SentryCrashStackEntryMapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryCrashStackEntryMapper.m; sourceTree = "<group>"; };
7B140899248791660035403D /* SentryCrashStackEntryMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashStackEntryMapperTests.swift; sourceTree = "<group>"; };
7B16FD012654F86B008177D3 /* SentrySysctlTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySysctlTests.swift; sourceTree = "<group>"; };
7B18DE3F28D9F748004845C6 /* SentryNSNotificationCenterWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryNSNotificationCenterWrapper.h; path = include/SentryNSNotificationCenterWrapper.h; sourceTree = "<group>"; };
7B18DE4128D9F794004845C6 /* SentryNSNotificationCenterWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryNSNotificationCenterWrapper.m; sourceTree = "<group>"; };
7B18DE4328D9F8F6004845C6 /* TestNSNotificationCenterWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestNSNotificationCenterWrapper.swift; sourceTree = "<group>"; };
7B18DE4928DA0C8B004845C6 /* SentryNSNotificationCenterWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSNotificationCenterWrapperTests.swift; sourceTree = "<group>"; };
7B26BBFA24C0A66D00A79CCC /* SentrySdkInfoNilTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySdkInfoNilTests.m; sourceTree = "<group>"; };
7B2A70D727D5F07F008B0D15 /* SentryANRTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryANRTrackerTests.swift; sourceTree = "<group>"; };
7B2A70DA27D607CF008B0D15 /* SentryThreadWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryThreadWrapper.h; path = include/SentryThreadWrapper.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1790,6 +1798,8 @@
D84793242788737D00BE8E99 /* SentryByteCountFormatter.m */,
7B2A70DA27D607CF008B0D15 /* SentryThreadWrapper.h */,
7B2A70DC27D6083D008B0D15 /* SentryThreadWrapper.m */,
7B18DE3F28D9F748004845C6 /* SentryNSNotificationCenterWrapper.h */,
7B18DE4128D9F794004845C6 /* SentryNSNotificationCenterWrapper.m */,
);
name = Helper;
sourceTree = "<group>";
Expand Down Expand Up @@ -2377,6 +2387,8 @@
7BF9EF872722D13000B5BBEF /* SentryTestObjCRuntimeWrapper.m */,
D85D3BE9278DF63D001B2889 /* SentryByteCountFormatterTests.swift */,
7B2A70DE27D60904008B0D15 /* SentryTestThreadWrapper.swift */,
7B18DE4328D9F8F6004845C6 /* TestNSNotificationCenterWrapper.swift */,
7B18DE4928DA0C8B004845C6 /* SentryNSNotificationCenterWrapperTests.swift */,
);
path = Helper;
sourceTree = "<group>";
Expand Down Expand Up @@ -2911,6 +2923,7 @@
7B14089624878F090035403D /* SentryCrashStackEntryMapper.h in Headers */,
63FE714920DA4C1100CDBAE8 /* SentryCrashStackCursor_Backtrace.h in Headers */,
7BFC169B2524995700FF6266 /* SentryMessage.h in Headers */,
7B18DE4028D9F748004845C6 /* SentryNSNotificationCenterWrapper.h in Headers */,
03F84D1E27DD414C008FE43F /* SentryBacktrace.hpp in Headers */,
63AA76991EB9C1C200D153DE /* SentryDefines.h in Headers */,
0A4EDEA928D3461B00FA67CB /* SentryPerformanceTracker+Private.h in Headers */,
Expand Down Expand Up @@ -3259,6 +3272,7 @@
63FE718120DA4C1100CDBAE8 /* SentryCrashDoctor.m in Sources */,
63FE713720DA4C1100CDBAE8 /* SentryCrashCPU_x86_64.c in Sources */,
8ECC674725C23A20000E2BF6 /* SentrySpanContext.m in Sources */,
7B18DE4228D9F794004845C6 /* SentryNSNotificationCenterWrapper.m in Sources */,
639FCFA91EBC80CC00778193 /* SentryFrame.m in Sources */,
8E564AEA267AF22600FE117D /* SentryNetworkTracker.m in Sources */,
15360CED2433A15500112302 /* SentryInstallation.m in Sources */,
Expand Down Expand Up @@ -3454,6 +3468,7 @@
7BD4BD4D27EB31820071F4FF /* SentryClientReportTests.swift in Sources */,
7B98D7EC25FB7C4900C5A389 /* SentryAppStateTests.swift in Sources */,
8EE017A126704CD500470616 /* SentryUIViewControllerPerformanceTrackerTests.swift in Sources */,
7B18DE4428D9F8F6004845C6 /* TestNSNotificationCenterWrapper.swift in Sources */,
7B5B94352657AD21002E474B /* SentryFramesTrackingIntegrationTests.swift in Sources */,
7BAF3DC8243DB90E008A5414 /* TestTransport.swift in Sources */,
7B0A54562523178700A71716 /* SentryScopeSwiftTests.swift in Sources */,
Expand Down Expand Up @@ -3520,6 +3535,7 @@
8E4A038525F76A7600000D77 /* Logger.swift in Sources */,
D8F6A24E288553A800320515 /* SentryPredicateDescriptorTests.swift in Sources */,
035E73CE27D5790A005EEB11 /* SentryThreadMetadataCacheTests.mm in Sources */,
7B18DE4A28DA0C8B004845C6 /* SentryNSNotificationCenterWrapperTests.swift in Sources */,
7BEFB044270B0F630025F808 /* SentryTracerObjCTests.m in Sources */,
7B0002322477F0520035FEF1 /* SentrySessionTests.m in Sources */,
7BC6EC08255C36DE0059822A /* SentryStacktraceTests.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/SentryAutoSessionTrackingIntegration.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "SentryAutoSessionTrackingIntegration.h"
#import "SentryDefaultCurrentDateProvider.h"
#import "SentryDependencyContainer.h"
#import "SentryLog.h"
#import "SentryOptions.h"
#import "SentrySDK.h"
Expand All @@ -24,7 +25,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options

SentrySessionTracker *tracker = [[SentrySessionTracker alloc]
initWithOptions:options
currentDateProvider:[SentryDefaultCurrentDateProvider sharedInstance]];
currentDateProvider:[SentryDefaultCurrentDateProvider sharedInstance]
notificationCenter:[SentryDependencyContainer sharedInstance].notificationCenterWrapper];
[tracker start];
self.tracker = tracker;

Expand Down
11 changes: 11 additions & 0 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <SentryDependencyContainer.h>
#import <SentryDispatchQueueWrapper.h>
#import <SentryHub.h>
#import <SentryNSNotificationCenterWrapper.h>
#import <SentrySDK+Private.h>
#import <SentryScreenshot.h>
#import <SentrySwizzleWrapper.h>
Expand Down Expand Up @@ -107,6 +108,16 @@ - (SentryDispatchQueueWrapper *)dispatchQueueWrapper
}
}

- (SentryNSNotificationCenterWrapper *)notificationCenterWrapper
{
@synchronized(sentryDependencyContainerLock) {
if (_notificationCenterWrapper == nil) {
_notificationCenterWrapper = [[SentryNSNotificationCenterWrapper alloc] init];
}
return _notificationCenterWrapper;
}
}

- (id<SentryRandom>)random
{
if (_random == nil) {
Expand Down
66 changes: 66 additions & 0 deletions Sources/Sentry/SentryNSNotificationCenterWrapper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#import "SentryNSNotificationCenterWrapper.h"

#if SENTRY_HAS_UIKIT
# import <UIKit/UIKit.h>
#elif TARGET_OS_OSX || TARGET_OS_MACCATALYST
# import <Cocoa/Cocoa.h>
#endif

NS_ASSUME_NONNULL_BEGIN

@implementation SentryNSNotificationCenterWrapper

#if SENTRY_HAS_UIKIT
+ (NSNotificationName)didBecomeActiveNotificationName
{
return UIApplicationDidBecomeActiveNotification;
}

+ (NSNotificationName)willResignActiveNotificationName
{
return UIApplicationWillResignActiveNotification;
}

+ (NSNotificationName)willTerminateNotificationName
{
return UIApplicationWillTerminateNotification;
}

#elif TARGET_OS_OSX || TARGET_OS_MACCATALYST
+ (NSNotificationName)didBecomeActiveNotificationName
{
return NSApplicationDidBecomeActiveNotification;
}

+ (NSNotificationName)willResignActiveNotificationName
{
return NSApplicationWillResignActiveNotification;
}

+ (NSNotificationName)willTerminateNotificationName
{
return NSApplicationWillTerminateNotification;
}
#endif

- (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSNotificationName)aName
{
[NSNotificationCenter.defaultCenter addObserver:observer
selector:aSelector
name:aName
object:nil];
}

- (void)removeObserver:(id)observer name:(NSNotificationName)aName
{
[NSNotificationCenter.defaultCenter removeObserver:observer name:aName object:nil];
}

- (void)removeObserver:(id)observer
{
[NSNotificationCenter.defaultCenter removeObserver:observer];
}

@end

NS_ASSUME_NONNULL_END
49 changes: 28 additions & 21 deletions Sources/Sentry/SentryOutOfMemoryTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <SentryLog.h>
#import <SentryMechanism.h>
#import <SentryMessage.h>
#import <SentryNSNotificationCenterWrapper.h>
#import <SentryOptions.h>
#import <SentryOutOfMemoryLogic.h>
#import <SentryOutOfMemoryTracker.h>
Expand Down Expand Up @@ -52,25 +53,28 @@ - (instancetype)initWithOptions:(SentryOptions *)options
- (void)start
{
#if SENTRY_HAS_UIKIT
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(didBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(didBecomeActive)
name:SentryNSNotificationCenterWrapper.didBecomeActiveNotificationName
object:nil];

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(didBecomeActive)
name:SentryHybridSdkDidBecomeActiveNotificationName
object:nil];

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(willResignActive)
name:UIApplicationWillResignActiveNotification
object:nil];
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(willResignActive)
name:SentryNSNotificationCenterWrapper.willResignActiveNotificationName
object:nil];

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(willTerminate)
name:UIApplicationWillTerminateNotification
object:nil];
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(willTerminate)
name:SentryNSNotificationCenterWrapper.willTerminateNotificationName
object:nil];

[self.dispatchQueue dispatchAsyncWithBlock:^{
if ([self.outOfMemoryLogic isOOM]) {
Expand Down Expand Up @@ -106,22 +110,25 @@ - (void)stop
#if SENTRY_HAS_UIKIT
// Remove the observers with the most specific detail possible, see
// https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver
[NSNotificationCenter.defaultCenter removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
[NSNotificationCenter.defaultCenter
removeObserver:self
name:SentryNSNotificationCenterWrapper.didBecomeActiveNotificationName
object:nil];

[NSNotificationCenter.defaultCenter
removeObserver:self
name:SentryHybridSdkDidBecomeActiveNotificationName
object:nil];

[NSNotificationCenter.defaultCenter removeObserver:self
name:UIApplicationWillResignActiveNotification
object:nil];
[NSNotificationCenter.defaultCenter
removeObserver:self
name:SentryNSNotificationCenterWrapper.willResignActiveNotificationName
object:nil];

[NSNotificationCenter.defaultCenter removeObserver:self
name:UIApplicationWillTerminateNotification
object:nil];
[NSNotificationCenter.defaultCenter
removeObserver:self
name:SentryNSNotificationCenterWrapper.willTerminateNotificationName
object:nil];
[self.appStateManager removeCurrentAppState];
#endif
}
Expand Down
Loading