1010# import " SentryEvent+Private.h"
1111# import " SentryFileManager.h"
1212# import " SentryHub+Private.h"
13+ # import " SentryInternalDefines.h"
1314# import " SentryLogC.h"
1415# import " SentryOptions.h"
1516# import " SentryRateLimits.h"
@@ -52,7 +53,6 @@ - (void)newSceneActivate;
5253@implementation SentrySessionReplayIntegration {
5354 BOOL _startedAsFullSession;
5455 SentryReplayOptions *_replayOptions;
55- SentryExperimentalOptions *_experimentalOptions;
5656 id <SentryNSNotificationCenterWrapper> _notificationCenter;
5757 id <SentryRateLimits> _rateLimits;
5858 id <SentryViewScreenshotProvider> _currentScreenshotProvider;
@@ -64,7 +64,14 @@ @implementation SentrySessionReplayIntegration {
6464 // replay absolutely needs segment 0 to make replay work.
6565 BOOL _rateLimited;
6666 id <SentryCurrentDateProvider> _dateProvider;
67- id <SentrySessionReplayEnvironmentCheckerProvider> _environmentChecker;
67+ }
68+
69+ + (BOOL )shouldEnableForOptions : (SentryOptions *)options
70+ {
71+ return [SentrySessionReplay
72+ shouldEnableSessionReplayWithEnvironmentChecker: SentryDependencyContainer.sharedInstance
73+ .sessionReplayEnvironmentChecker
74+ experimentalOptions: options.experimental];
6875}
6976
7077- (instancetype )init
@@ -77,39 +84,34 @@ - (instancetype)initForManualUse:(nonnull SentryOptions *)options
7784{
7885 if (self = [super init ]) {
7986 [self setupWith: options.sessionReplay
80- experimentalOptions: options.experimental
8187 enableTouchTracker: options.enableSwizzling
8288 enableViewRendererV2: options.sessionReplay.enableViewRendererV2
8389 enableFastViewRendering: options.sessionReplay.enableFastViewRendering];
84- [self startWithOptions: options.sessionReplay
85- experimentalOptions: options.experimental
86- fullSession: YES ];
90+ [self startWithOptions: options.sessionReplay fullSession: YES ];
8791 }
8892 return self;
8993}
9094
9195- (BOOL )installWithOptions : (nonnull SentryOptions *)options
9296{
93- if ([super installWithOptions: options] == NO ) {
97+ if ([super installWithOptions: options] == NO ||
98+ [SentrySessionReplayIntegration shouldEnableForOptions: options] == NO ) {
9499 return NO ;
95100 }
96101
97102 [self setupWith: options.sessionReplay
98- experimentalOptions: options.experimental
99103 enableTouchTracker: options.enableSwizzling
100104 enableViewRendererV2: options.sessionReplay.enableViewRendererV2
101105 enableFastViewRendering: options.sessionReplay.enableFastViewRendering];
102106 return YES ;
103107}
104108
105109- (void )setupWith : (SentryReplayOptions *)replayOptions
106- experimentalOptions : (SentryExperimentalOptions *)experimentalOptions
107110 enableTouchTracker : (BOOL )touchTracker
108111 enableViewRendererV2 : (BOOL )enableViewRendererV2
109112 enableFastViewRendering : (BOOL )enableFastViewRendering
110113{
111114 _replayOptions = replayOptions;
112- _experimentalOptions = experimentalOptions;
113115 _rateLimits = SentryDependencyContainer.sharedInstance .rateLimits ;
114116 _dateProvider = SentryDependencyContainer.sharedInstance .dateProvider ;
115117
@@ -140,7 +142,6 @@ - (void)setupWith:(SentryReplayOptions *)replayOptions
140142
141143 _notificationCenter = SentryDependencyContainer.sharedInstance .notificationCenterWrapper ;
142144 _dateProvider = SentryDependencyContainer.sharedInstance .dateProvider ;
143- _environmentChecker = SentryDependencyContainer.sharedInstance .sessionReplayEnvironmentChecker ;
144145
145146 // We use the dispatch queue provider as a factory to create the queues, but store the queues
146147 // directly in this instance, so they get deallocated when the integration is deallocated.
@@ -338,9 +339,7 @@ - (void)runReplayForAvailableWindow
338339 if ([SentryDependencyContainer.sharedInstance.application getWindows ].count > 0 ) {
339340 SENTRY_LOG_DEBUG (@" [Session Replay] Running replay for available window" );
340341 // If a window its already available start replay right away
341- [self startWithOptions: _replayOptions
342- experimentalOptions: _experimentalOptions
343- fullSession: _startedAsFullSession];
342+ [self startWithOptions: _replayOptions fullSession: _startedAsFullSession];
344343 } else if (@available (iOS 13.0 , tvOS 13.0 , *)) {
345344 SENTRY_LOG_DEBUG (
346345 @" [Session Replay] Waiting for a scene to be available to started the replay" );
@@ -360,27 +359,22 @@ - (void)newSceneActivate
360359 removeObserver: self
361360 name: UISceneDidActivateNotification
362361 object: nil ];
363- [self startWithOptions: _replayOptions
364- experimentalOptions: _experimentalOptions
365- fullSession: _startedAsFullSession];
362+ [self startWithOptions: _replayOptions fullSession: _startedAsFullSession];
366363 }
367364}
368365
369366- (void )startWithOptions : (SentryReplayOptions *)replayOptions
370- experimentalOptions : (SentryExperimentalOptions *)experimentalOptions
371367 fullSession : (BOOL )shouldReplayFullSession
372368{
373369 SENTRY_LOG_DEBUG (@" [Session Replay] Starting session" );
374370 [self startWithOptions: replayOptions
375- experimentalOptions: experimentalOptions
376371 screenshotProvider: _currentScreenshotProvider ?: _viewPhotographer
377372 breadcrumbConverter: _currentBreadcrumbConverter
378373 ?: [[SentrySRDefaultBreadcrumbConverter alloc ] init ]
379374 fullSession: shouldReplayFullSession];
380375}
381376
382377- (void )startWithOptions : (SentryReplayOptions *)replayOptions
383- experimentalOptions : (SentryExperimentalOptions *)experimentalOptions
384378 screenshotProvider : (id <SentryViewScreenshotProvider>)screenshotProvider
385379 breadcrumbConverter : (id <SentryReplayBreadcrumbConverter>)breadcrumbConverter
386380 fullSession : (BOOL )shouldReplayFullSession
@@ -415,16 +409,14 @@ - (void)startWithOptions:(SentryReplayOptions *)replayOptions
415409
416410 SentryDisplayLinkWrapper *displayLinkWrapper = [[SentryDisplayLinkWrapper alloc ] init ];
417411 self.sessionReplay = [[SentrySessionReplay alloc ] initWithReplayOptions: replayOptions
418- experimentalOptions: experimentalOptions
419412 replayFolderPath: docs
420413 screenshotProvider: screenshotProvider
421414 replayMaker: replayMaker
422415 breadcrumbConverter: breadcrumbConverter
423416 touchTracker: _touchTracker
424417 dateProvider: _dateProvider
425418 delegate: self
426- displayLinkWrapper: displayLinkWrapper
427- environmentChecker: _environmentChecker];
419+ displayLinkWrapper: displayLinkWrapper];
428420
429421 [self .sessionReplay
430422 startWithRootView: [SentryDependencyContainer.sharedInstance.application getWindows ]
@@ -456,15 +448,19 @@ - (nullable NSURL *)replayDirectory
456448 return [dir URLByAppendingPathComponent: SENTRY_REPLAY_FOLDER];
457449}
458450
459- - (void )saveCurrentSessionInfo : (SentryId *)sessionId
451+ - (void )saveCurrentSessionInfo : (SentryId *_Nullable )sessionId
460452 path : (NSString *)path
461453 options : (SentryReplayOptions *)options
462454{
463455 SENTRY_LOG_DEBUG (@" [Session Replay] Saving current session info for session: %@ to path: %@ " ,
464456 sessionId, path);
465- NSDictionary *info =
466- [[NSDictionary alloc ] initWithObjectsAndKeys: sessionId.sentryIdString, @" replayId" ,
467- path.lastPathComponent, @" path" , @(options.onErrorSampleRate), @" errorSampleRate" , nil ];
457+ NSMutableDictionary *info = [NSMutableDictionary new ];
458+ if (sessionId != nil ) {
459+ [info setObject: SENTRY_UNWRAP_NULLABLE (SentryId, sessionId).sentryIdString
460+ forKey: @" replayId" ];
461+ }
462+ [info setObject: path.lastPathComponent forKey: @" path" ];
463+ [info setObject: @(options.onErrorSampleRate) forKey: @" errorSampleRate" ];
468464
469465 NSData *data = [SentrySerializationSwift dataWithJSONObject: info];
470466
0 commit comments