Skip to content

Commit 9a32d52

Browse files
authored
fix: Lazily access UIApplication.shared (#6264)
Fixes null UIApplication by accessing it lazily instead of storing it in an instance variable. Also updated the Swift nullability to properly reflect that this value is nullable. Fixes GH-6265, GH-6270
1 parent 2ec2700 commit 9a32d52

19 files changed

+184
-85
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ jobs:
243243
runs-on: macos-26
244244
platform: "iOS"
245245
xcode: "26.0"
246-
test-destination-os: "latest"
246+
test-destination-os: "26.0"
247247
device: "iPhone 17 Pro"
248248
scheme: "Sentry"
249249

@@ -272,7 +272,7 @@ jobs:
272272
runs-on: macos-26
273273
platform: "macOS"
274274
xcode: "26.0"
275-
test-destination-os: "latest"
275+
test-destination-os: "26.0"
276276
scheme: "Sentry"
277277

278278
# Catalyst. We test the latest version, as the risk something breaking on Catalyst and not
@@ -328,7 +328,7 @@ jobs:
328328
runs-on: macos-26
329329
platform: "tvOS"
330330
xcode: "26.0"
331-
test-destination-os: "latest"
331+
test-destination-os: "26.0"
332332
device: "Apple TV"
333333
scheme: "Sentry"
334334

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Fix crash from null UIApplication in SwiftUI apps (#6264)
8+
39
## 8.56.1
410

511
> [!Warning]

Sentry.xcodeproj/project.pbxproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,6 @@
10461046
FA6555162E30182B009917BC /* SentrySDKInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = FA6555152E30182B009917BC /* SentrySDKInternal.m */; };
10471047
FA65551A2E3018A3009917BC /* SentrySDKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6555192E30189E009917BC /* SentrySDKTests.swift */; };
10481048
FA66143A2E4B593900657755 /* SentryApplicationExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6614392E4B593000657755 /* SentryApplicationExtensions.swift */; };
1049-
FA6614FC2E4B8E1A00657755 /* TestSentryUIApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6614FB2E4B8E1500657755 /* TestSentryUIApplication.swift */; };
10501049
FA6615052E4BA4D700657755 /* ThreadSafeApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6615042E4BA4D200657755 /* ThreadSafeApplication.swift */; };
10511050
FA67DCC12DDBD4C800896B02 /* SentrySDKLog+Configure.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCC02DDBD4C800896B02 /* SentrySDKLog+Configure.swift */; };
10521051
FA67DCF52DDBD4EA00896B02 /* SentryCurrentDateProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCCA2DDBD4EA00896B02 /* SentryCurrentDateProvider.swift */; };
@@ -1090,6 +1089,8 @@
10901089
FA7206DF2E0B37850072FDD4 /* SentryProfileCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = FA7206DE2E0B37780072FDD4 /* SentryProfileCollector.h */; };
10911090
FA7206E12E0B37C80072FDD4 /* SentryProfileCollector.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA7206E02E0B37C60072FDD4 /* SentryProfileCollector.mm */; };
10921091
FA8A36182DEAA1EB0058D883 /* SentryThread+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */; };
1092+
FA8AFCFA2E844AB6007A0E18 /* SentryThreadsafeApplicationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8AFCF42E844AB1007A0E18 /* SentryThreadsafeApplicationTests.swift */; };
1093+
FA8AFDAC2E84FAEE007A0E18 /* TestSentryUIApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6614FB2E4B8E1500657755 /* TestSentryUIApplication.swift */; };
10931094
FA8E58F12E0AD4270049F69D /* SentryDispatchQueueWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8E58F02E0AD4220049F69D /* SentryDispatchQueueWrapper.swift */; };
10941095
FA90FAA82E06614E008CAAE8 /* SentryExtraPackages.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA90FAA72E06614B008CAAE8 /* SentryExtraPackages.swift */; };
10951096
FA90FAFD2E070A3B008CAAE8 /* SentryURLRequestFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA90FAFC2E070A3B008CAAE8 /* SentryURLRequestFactory.swift */; };
@@ -1111,16 +1112,16 @@
11111112
FACEED132E3179A10007B4AC /* SentyOptionsInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = FACEED122E3179A10007B4AC /* SentyOptionsInternal.m */; };
11121113
FAE2DAB82E1F317900262307 /* SentryProfilingSwiftHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = FAE2DAB72E1F317900262307 /* SentryProfilingSwiftHelpers.m */; };
11131114
FAE2DABA2E1F318900262307 /* SentryProfilingSwiftHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE2DAB92E1F318900262307 /* SentryProfilingSwiftHelpers.h */; };
1115+
FAE579842E7CF21800B710F9 /* SentryMigrateSessionInit.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE5797E2E7CF21300B710F9 /* SentryMigrateSessionInit.swift */; };
11141116
FAE5798D2E7D9D4C00B710F9 /* SentrySysctl.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */; };
11151117
FAE579BA2E7DBE9900B710F9 /* SentryGlobalEventProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579B42E7DBE9400B710F9 /* SentryGlobalEventProcessor.swift */; };
11161118
FAE579C22E7DDDE700B710F9 /* SentryThreadWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579BC2E7DDDE400B710F9 /* SentryThreadWrapper.swift */; };
1117-
FAE579842E7CF21800B710F9 /* SentryMigrateSessionInit.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE5797E2E7CF21300B710F9 /* SentryMigrateSessionInit.swift */; };
11181119
FAE579CC2E7DE14900B710F9 /* SentryFrameRemover.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579C62E7DE14400B710F9 /* SentryFrameRemover.swift */; };
11191120
FAE80C242E4695B40010A595 /* SentryEvent+Serialize.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */; };
11201121
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; };
11211122
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
1122-
FAEEC0522E75E55F00E79CA9 /* SentrySerializationSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */; };
11231123
FAEEBFE22E736D4B00E79CA9 /* SentryViewHierarchyProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEEBFDC2E736D4100E79CA9 /* SentryViewHierarchyProvider.swift */; };
1124+
FAEEC0522E75E55F00E79CA9 /* SentrySerializationSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */; };
11241125
FAEFA12F2E4FAE1900C431D9 /* SentrySDKSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEFA1292E4FAE1700C431D9 /* SentrySDKSettings.swift */; };
11251126
FAF120182E70C08F006E1DA3 /* SentryEnvelopeHeaderHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FAF120122E70C088006E1DA3 /* SentryEnvelopeHeaderHelper.h */; };
11261127
FAF1201A2E70C0EE006E1DA3 /* SentryEnvelopeHeaderHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FAF120192E70C0EA006E1DA3 /* SentryEnvelopeHeaderHelper.m */; };
@@ -2436,6 +2437,7 @@
24362437
FA7206DE2E0B37780072FDD4 /* SentryProfileCollector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryProfileCollector.h; sourceTree = "<group>"; };
24372438
FA7206E02E0B37C60072FDD4 /* SentryProfileCollector.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryProfileCollector.mm; sourceTree = "<group>"; };
24382439
FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryThread+Private.h"; path = "include/SentryThread+Private.h"; sourceTree = "<group>"; };
2440+
FA8AFCF42E844AB1007A0E18 /* SentryThreadsafeApplicationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryThreadsafeApplicationTests.swift; sourceTree = "<group>"; };
24392441
FA8E58F02E0AD4220049F69D /* SentryDispatchQueueWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDispatchQueueWrapper.swift; sourceTree = "<group>"; };
24402442
FA90FAA72E06614B008CAAE8 /* SentryExtraPackages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExtraPackages.swift; sourceTree = "<group>"; };
24412443
FA90FAFC2E070A3B008CAAE8 /* SentryURLRequestFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryURLRequestFactory.swift; sourceTree = "<group>"; };
@@ -2466,8 +2468,8 @@
24662468
FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = "<group>"; };
24672469
FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = "<group>"; };
24682470
FAEC273E2DF393E000878871 /* NSData+Unzip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Unzip.h"; sourceTree = "<group>"; };
2469-
FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySerializationSwift.swift; sourceTree = "<group>"; };
24702471
FAEEBFDC2E736D4100E79CA9 /* SentryViewHierarchyProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryViewHierarchyProvider.swift; sourceTree = "<group>"; };
2472+
FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySerializationSwift.swift; sourceTree = "<group>"; };
24712473
FAEFA1292E4FAE1700C431D9 /* SentrySDKSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySDKSettings.swift; sourceTree = "<group>"; };
24722474
FAF120122E70C088006E1DA3 /* SentryEnvelopeHeaderHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeHeaderHelper.h; path = include/SentryEnvelopeHeaderHelper.h; sourceTree = "<group>"; };
24732475
FAF120192E70C0EA006E1DA3 /* SentryEnvelopeHeaderHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEnvelopeHeaderHelper.m; sourceTree = "<group>"; };
@@ -2997,6 +2999,7 @@
29972999
7B0002312477F0520035FEF1 /* SentrySessionTests.m */,
29983000
63AA75951EB8AEDB00D153DE /* SentryTests.m */,
29993001
63AA75941EB8AEDB00D153DE /* Info.plist */,
3002+
FA6614FB2E4B8E1500657755 /* TestSentryUIApplication.swift */,
30003003
7BAF3DB4243C743E008A5414 /* SentryClientTests.swift */,
30013004
A8AFFCD12907DA7600967CD7 /* SentryHttpStatusCodeRangeTests.swift */,
30023005
7B6CC50124EE5A42001816D7 /* SentryHubTests.swift */,
@@ -4430,14 +4433,14 @@
44304433
D81FDF0F280E9FEC0045E0E4 /* Tools */ = {
44314434
isa = PBXGroup;
44324435
children = (
4433-
FA6614FB2E4B8E1500657755 /* TestSentryUIApplication.swift */,
44344436
FAAB2EDF2E4BE96F00FE8B7E /* TestSentryNSApplication.swift */,
44354437
D43A2A132DD4815E00114724 /* SentryWeakMapTests.swift */,
44364438
D4009EA02D77196F0007AF30 /* ViewCapture */,
44374439
D81FDF10280EA0080045E0E4 /* SentryScreenshotSourceTests.swift */,
44384440
D8F6A24C2885534E00320515 /* SentryPredicateDescriptorTests.swift */,
44394441
0A5370A028A3EC2400B2DCDE /* SentryViewHierarchyProviderTests.swift */,
44404442
D8CB742A294B1DD000A5F964 /* SentryUIApplicationTests.swift */,
4443+
FA8AFCF42E844AB1007A0E18 /* SentryThreadsafeApplicationTests.swift */,
44414444
D8CB742C294B294B00A5F964 /* MockUIScene.h */,
44424445
D8CB742D294B294B00A5F964 /* MockUIScene.m */,
44434446
D84541172A2DC2CD00E2B11C /* SentryBinaryImageCacheTests.swift */,
@@ -6118,6 +6121,7 @@
61186121
7B0002322477F0520035FEF1 /* SentrySessionTests.m in Sources */,
61196122
62CFD9AD2C99770B00834E1B /* SentryInvalidJSONString.m in Sources */,
61206123
62375FB92B47F9F000CC55F1 /* SentryDependencyContainerTests.swift in Sources */,
6124+
FA8AFDAC2E84FAEE007A0E18 /* TestSentryUIApplication.swift in Sources */,
61216125
7BC6EC08255C36DE0059822A /* SentryStacktraceTests.swift in Sources */,
61226126
F49D419A2DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift in Sources */,
61236127
D88817DD26D72BA500BF2251 /* SentryTraceContextTests.swift in Sources */,
@@ -6244,12 +6248,12 @@
62446248
7BC6EC0C255C3DF80059822A /* SentryThreadTests.swift in Sources */,
62456249
D42E48572D48DF1600D251BC /* SentryBuildAppStartSpansTests.swift in Sources */,
62466250
F443DB272E09BE8C009A9045 /* LoadValidatorTests.swift in Sources */,
6251+
FA8AFCFA2E844AB6007A0E18 /* SentryThreadsafeApplicationTests.swift in Sources */,
62476252
D884A20527C80F6300074664 /* SentryCoreDataTrackerTest.swift in Sources */,
62486253
8E70B10125CB8695002B3155 /* SentrySpanIdTests.swift in Sources */,
62496254
62E2119A2DAE99FC007D7262 /* SentryAsyncSafeLog.m in Sources */,
62506255
84EB21962BF01CEA00EDDA28 /* SentryCrashInstallationTests.swift in Sources */,
62516256
7BFE7A0A27A1B6B000D2B66E /* SentryWatchdogTerminationTrackingIntegrationTests.swift in Sources */,
6252-
FA6614FC2E4B8E1A00657755 /* TestSentryUIApplication.swift in Sources */,
62536257
D8292D7D2A39A027009872F7 /* UrlSanitizedTests.swift in Sources */,
62546258
621D22012DBB7E09006F9C48 /* SentryANRTrackerV1IntegrationTests.swift in Sources */,
62556259
7BA61CAF247BBF3C00C130A8 /* SentryDebugImageProviderTests.swift in Sources */,

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@
5858
#define SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK \
5959
SENTRY_DISABLE_THREAD_SANITIZER("Double-checked locks produce false alarms.")
6060

61+
typedef id<SentryApplication> _Nullable (^SentryApplicationProviderBlock)(void);
62+
// Declare the application provider block at the top level to prevent capturing 'self'
63+
// from the dependency container, which would create cyclic dependencies and memory leaks.
64+
SentryApplicationProviderBlock defaultApplicationProvider = ^id<SentryApplication> _Nullable()
65+
{
66+
#if SENTRY_HAS_UIKIT
67+
return UIApplication.sharedApplication;
68+
#elif TARGET_OS_OSX
69+
return NSApplication.sharedApplication;
70+
#endif
71+
return nil;
72+
};
73+
6174
@interface SentryFileManager () <SentryFileManagerProtocol>
6275
@end
6376

@@ -151,12 +164,9 @@ - (instancetype)init
151164
_crashWrapper = [[SentryCrashWrapper alloc] initWithProcessInfoWrapper:_processInfoWrapper];
152165
#if SENTRY_HAS_UIKIT
153166
_uiDeviceWrapper = SentryDependencies.uiDeviceWrapper;
154-
_application = UIApplication.sharedApplication;
155167
_threadsafeApplication = [[SentryThreadsafeApplication alloc]
156-
initWithInitialState:_application.unsafeApplicationState
157-
notificationCenter:_notificationCenterWrapper];
158-
#elif TARGET_OS_OSX
159-
_application = NSApplication.sharedApplication;
168+
initWithApplicationProvider:defaultApplicationProvider
169+
notificationCenter:_notificationCenterWrapper];
160170
#endif // SENTRY_HAS_UIKIT
161171

162172
_extraContextProvider =
@@ -189,6 +199,17 @@ - (instancetype)init
189199
return self;
190200
}
191201

202+
- (nullable id<SentryApplication>)application
203+
{
204+
#if defined(SENTRY_TEST) || defined(SENTRY_TEST_CI)
205+
id<SentryApplication> override = self.applicationOverride;
206+
if (override) {
207+
return override;
208+
}
209+
#endif
210+
return defaultApplicationProvider();
211+
}
212+
192213
- (nullable SentryFileManager *)fileManager SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
193214
{
194215
SENTRY_LAZY_INIT(_fileManager, ({
@@ -297,8 +318,9 @@ - (SentryViewHierarchyProvider *)viewHierarchyProvider SENTRY_THREAD_SANITIZER_D
297318
# if SENTRY_HAS_UIKIT
298319

299320
SENTRY_LAZY_INIT(_viewHierarchyProvider,
300-
[[SentryViewHierarchyProvider alloc] initWithDispatchQueueWrapper:self.dispatchQueueWrapper
301-
sentryUIApplication:self.application]);
321+
[[SentryViewHierarchyProvider alloc]
322+
initWithDispatchQueueWrapper:self.dispatchQueueWrapper
323+
applicationProvider:defaultApplicationProvider]);
302324
# else
303325
SENTRY_LOG_DEBUG(
304326
@"SentryDependencyContainer.viewHierarchyProvider only works with UIKit "
@@ -445,7 +467,7 @@ - (SentryGlobalEventProcessor *)globalEventProcessor SENTRY_THREAD_SANITIZER_DOU
445467
- (SentrySessionTracker *)getSessionTrackerWithOptions:(SentryOptions *)options
446468
{
447469
return [[SentrySessionTracker alloc] initWithOptions:options
448-
application:self.application
470+
applicationProvider:defaultApplicationProvider
449471
dateProvider:self.dateProvider
450472
notificationCenter:self.notificationCenterWrapper];
451473
}

Sources/Sentry/SentrySessionTracker.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ @interface SentrySessionTracker ()
2626
@property (nonatomic, assign) BOOL wasStartSessionCalled;
2727
@property (nonatomic, assign) BOOL subscribedToNotifications;
2828

29-
@property (nonatomic, strong) id<SentryApplication> application;
29+
@property (nonatomic, strong) id<SentryApplication> _Nullable (^applicationProvider)(void);
3030
@property (nonatomic, strong) id<SentryCurrentDateProvider> dateProvider;
3131
@property (nonatomic, strong) id<SentryNSNotificationCenterWrapper> notificationCenter;
3232

@@ -35,14 +35,14 @@ @interface SentrySessionTracker ()
3535
@implementation SentrySessionTracker
3636

3737
- (instancetype)initWithOptions:(SentryOptions *)options
38-
application:(id<SentryApplication>)application
38+
applicationProvider:(id<SentryApplication> _Nullable (^)(void))applicationProvider
3939
dateProvider:(id<SentryCurrentDateProvider>)dateProvider
4040
notificationCenter:(id<SentryNSNotificationCenterWrapper>)notificationCenter
4141
{
4242
if (self = [super init]) {
4343
self.options = options;
4444
self.wasStartSessionCalled = NO;
45-
self.application = application;
45+
self.applicationProvider = applicationProvider;
4646
self.dateProvider = dateProvider;
4747
self.notificationCenter = notificationCenter;
4848
}
@@ -101,6 +101,11 @@ - (void)start
101101
#endif
102102
}
103103

104+
- (id<SentryApplication> _Nullable)application
105+
{
106+
return self.applicationProvider();
107+
}
108+
104109
- (void)stop
105110
{
106111
[[SentrySDKInternal currentHub] endSession];

Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ SENTRY_NO_INIT
9393
@property (nonatomic, strong) id<SentryProcessInfoSource> processInfoWrapper;
9494
@property (nonatomic, strong) SentrySysctl *sysctlWrapper;
9595
@property (nonatomic, strong) id<SentryRateLimits> rateLimits;
96-
@property (nonatomic, strong) id<SentryApplication> application;
9796
@property (nonatomic, strong) SentryThreadsafeApplication *threadsafeApplication;
9897

9998
#if SENTRY_HAS_REACHABILITY
@@ -119,6 +118,8 @@ SENTRY_NO_INIT
119118
- (id<SentryANRTracker>)getANRTracker:(NSTimeInterval)timeout isV2Enabled:(BOOL)isV2Enabled;
120119
#endif // SENTRY_HAS_UIKIT
121120

121+
- (nullable id<SentryApplication>)application;
122+
122123
#if SENTRY_TARGET_PROFILING_SUPPORTED
123124
@property (nonatomic, strong) SentrySystemWrapper *systemWrapper;
124125
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
@@ -155,6 +156,12 @@ SENTRY_NO_INIT
155156
@property (nonatomic, strong) SentryGlobalEventProcessor *globalEventProcessor;
156157
- (SentrySessionTracker *)getSessionTrackerWithOptions:(SentryOptions *)options;
157158

159+
#if defined(SENTRY_TEST) || defined(SENTRY_TEST_CI)
160+
// Some tests rely on this value being grabbed from the global dependency container
161+
// rather than using dependency injection.
162+
@property (nonatomic, strong) id<SentryApplication> applicationOverride;
163+
#endif
164+
158165
@end
159166

160167
NS_ASSUME_NONNULL_END

Sources/Sentry/include/SentrySessionTracker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
@class SentryEvent;
44
@class SentryOptions;
55

6-
@protocol SentryNSNotificationCenterWrapper;
76
@protocol SentryApplication;
7+
@protocol SentryNSNotificationCenterWrapper;
88
@protocol SentryCurrentDateProvider;
99

1010
NS_ASSUME_NONNULL_BEGIN
@@ -18,7 +18,7 @@ NS_SWIFT_NAME(SessionTracker)
1818
SENTRY_NO_INIT
1919

2020
- (instancetype)initWithOptions:(SentryOptions *)options
21-
application:(id<SentryApplication>)application
21+
applicationProvider:(id<SentryApplication> _Nullable (^)(void))applicationProvider
2222
dateProvider:(id<SentryCurrentDateProvider>)dateProvider
2323
notificationCenter:(id<SentryNSNotificationCenterWrapper>)notificationCenter;
2424

0 commit comments

Comments
 (0)