Skip to content

Commit 5de0617

Browse files
committed
Remove SENTRY_HAS_REACHABILITY macro and enable SentryReachability to all platforms
1 parent d8b7e03 commit 5de0617

File tree

6 files changed

+21
-49
lines changed

6 files changed

+21
-49
lines changed

Sources/Sentry/Public/SentryDefines.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@
6565
-(instancetype)init NS_UNAVAILABLE; \
6666
+(instancetype) new NS_UNAVAILABLE;
6767

68-
#if !TARGET_OS_WATCH && !(TARGET_OS_VISION && SENTRY_NO_UIKIT == 1)
69-
# define SENTRY_HAS_REACHABILITY 1
70-
#else
71-
# define SENTRY_HAS_REACHABILITY 0
72-
#endif
73-
7468
@class SentryBreadcrumb;
7569
@class SentryEvent;
7670
@class SentrySamplingContext;

Sources/Sentry/SentryBreadcrumbTracker.m

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
static NSString *const SentryBreadcrumbTrackerSwizzleSendAction
2626
= @"SentryBreadcrumbTrackerSwizzleSendAction";
2727

28-
@interface SentryBreadcrumbTracker ()
29-
#if SENTRY_HAS_REACHABILITY
30-
<SentryReachabilityObserver>
31-
#endif // !TARGET_OS_WATCH
28+
@interface SentryBreadcrumbTracker () <SentryReachabilityObserver>
3229

3330
@property (nonatomic, weak) id<SentryBreadcrumbDelegate> delegate;
3431

@@ -38,12 +35,10 @@ @implementation SentryBreadcrumbTracker {
3835
BOOL _reportAccessibilityIdentifier;
3936
}
4037

41-
#if SENTRY_HAS_REACHABILITY
4238
- (void)dealloc
4339
{
4440
[SentryDependencyContainer.sharedInstance.reachability removeObserver:self];
4541
}
46-
#endif // !TARGET_OS_WATCH
4742

4843
- (instancetype)initReportAccessibilityIdentifier:(BOOL)report
4944
{
@@ -58,9 +53,7 @@ - (void)startWithDelegate:(id<SentryBreadcrumbDelegate>)delegate
5853
_delegate = delegate;
5954
[self addEnabledCrumb];
6055
[self trackApplicationNotifications];
61-
#if SENTRY_HAS_REACHABILITY
6256
[self trackNetworkConnectivityChanges];
63-
#endif // !TARGET_OS_WATCH
6457
}
6558

6659
#if SENTRY_HAS_UIKIT
@@ -80,9 +73,7 @@ - (void)stop
8073
removeSwizzleSendActionForKey:SentryBreadcrumbTrackerSwizzleSendAction];
8174
#endif // SENTRY_HAS_UIKIT
8275
_delegate = nil;
83-
#if SENTRY_HAS_REACHABILITY
8476
[self stopTrackNetworkConnectivityChanges];
85-
#endif // SENTRY_HAS_REACHABILITY
8677
}
8778

8879
- (void)trackApplicationNotifications
@@ -142,7 +133,6 @@ - (void)trackApplicationNotifications
142133
#endif // SENTRY_HAS_UIKIT || SENTRY_TARGET_MACOS_HAS_UI
143134
}
144135

145-
#if SENTRY_HAS_REACHABILITY
146136
- (void)trackNetworkConnectivityChanges
147137
{
148138
[SentryDependencyContainer.sharedInstance.reachability addObserver:self];
@@ -162,8 +152,6 @@ - (void)connectivityChanged:(BOOL)connected typeDescription:(nonnull NSString *)
162152
[self.delegate addBreadcrumb:crumb];
163153
}
164154

165-
#endif // SENTRY_HAS_REACHABILITY
166-
167155
- (void)addBreadcrumbWithType:(NSString *)type
168156
withCategory:(NSString *)category
169157
withLevel:(SentryLevel)level

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ + (instancetype)sharedInstance
112112
+ (void)reset
113113
{
114114
@synchronized(sentryDependencyContainerInstanceLock) {
115-
#if SENTRY_HAS_REACHABILITY
116115
[instance->_reachability removeAllObservers];
117-
#endif // SENTRY_HAS_REACHABILITY
118116

119117
#if SENTRY_HAS_UIKIT
120118
[instance->_framesTracker stop];
@@ -182,9 +180,7 @@ - (instancetype)init
182180
andRateLimitParser:rateLimitParser
183181
currentDateProvider:_dateProvider];
184182

185-
#if SENTRY_HAS_REACHABILITY
186183
_reachability = [[SentryReachability alloc] init];
187-
#endif // SENTRY_HAS_REACHABILITY
188184

189185
isInitialializingDependencyContainer = NO;
190186
}

Sources/Sentry/SentryHttpTransport.m

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
#import "SentrySerialization.h"
1717
#import "SentrySwift.h"
1818

19-
@interface SentryHttpTransport ()
20-
#if SENTRY_HAS_REACHABILITY
21-
<SentryReachabilityObserver>
22-
#endif // SENTRY_HAS_REACHABILITY
19+
@interface SentryHttpTransport () <SentryReachabilityObserver>
2320

2421
@property (nonatomic, readonly) NSTimeInterval cachedEnvelopeSendDelay;
2522
@property (nonatomic, strong) SentryFileManager *fileManager;
@@ -92,14 +89,11 @@ - (id)initWithDsn:(SentryDsn *)dsn
9289

9390
[self sendAllCachedEnvelopes];
9491

95-
#if SENTRY_HAS_REACHABILITY
9692
[SentryDependencyContainer.sharedInstance.reachability addObserver:self];
97-
#endif // SENTRY_HAS_REACHABILITY
9893
}
9994
return self;
10095
}
10196

102-
#if SENTRY_HAS_REACHABILITY
10397
- (void)connectivityChanged:(BOOL)connected typeDescription:(nonnull NSString *)typeDescription
10498
{
10599
if (connected) {
@@ -114,7 +108,6 @@ - (void)dealloc
114108
{
115109
[SentryDependencyContainer.sharedInstance.reachability removeObserver:self];
116110
}
117-
#endif // SENTRY_HAS_REACHABILITY
118111

119112
- (void)sendEnvelope:(SentryEnvelope *)envelope
120113
{

Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@class SentryOptions;
2626
@class SentrySessionTracker;
2727
@class SentryGlobalEventProcessor;
28+
@class SentryReachability;
2829

2930
@protocol SentryANRTracker;
3031
@protocol SentryRandomProtocol;
@@ -54,10 +55,6 @@
5455
@protocol SentryUIDeviceWrapper;
5556
#endif // TARGET_OS_IOS
5657

57-
#if !TARGET_OS_WATCH
58-
@class SentryReachability;
59-
#endif // !TARGET_OS_WATCH
60-
6158
NS_ASSUME_NONNULL_BEGIN
6259

6360
/**
@@ -95,10 +92,7 @@ SENTRY_NO_INIT
9592
@property (nonatomic, strong) id<SentryRateLimits> rateLimits;
9693
@property (nonatomic, strong) id<SentryApplication> application;
9794
@property (nonatomic, strong) SentryThreadsafeApplication *threadsafeApplication;
98-
99-
#if SENTRY_HAS_REACHABILITY
10095
@property (nonatomic, strong) SentryReachability *reachability;
101-
#endif // !TARGET_OS_WATCH
10296

10397
#if SENTRY_HAS_UIKIT
10498
@property (nonatomic, strong) id<SentryUIDeviceWrapper> uiDeviceWrapper;

Sources/Swift/Networking/SentryReachability.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import Foundation
22
import Network
33

4-
#if !os(watchOS) && !((swift(>=5.9) && os(visionOS)) && SENTRY_NO_UIKIT)
5-
64
// MARK: - SentryConectivity
7-
@objc
5+
#if DEBUG || SENTRY_TEST || SENTRY_TEST_CI
6+
@objc @_spi(Private)
87
public enum SentryConnectivity: Int {
98
case cellular
109
case wiFi
1110
case none
12-
11+
}
12+
#else
13+
@objc
14+
enum SentryConnectivity: Int {
15+
case cellular
16+
case wiFi
17+
case none
18+
}
19+
#endif // DEBUG || SENTRY_TEST || SENTRY_TEST_CI
20+
21+
extension SentryConnectivity {
1322
func toString() -> String {
1423
switch self {
1524
case .cellular:
@@ -68,7 +77,7 @@ public class SentryReachability: NSObject {
6877
}
6978
#endif // DEBUG || SENTRY_TEST || SENTRY_TEST_CI
7079

71-
if #available(iOS 12.0, macOS 10.14, tvOS 12.0, *) {
80+
if #available(iOS 12.0, macOS 10.14, tvOS 12.0, visionOS 1.0, watchOS 5.0, *) {
7281
// If we don't use the main queue to start the monitor, the app seems to freeze on iOS 14.8 (SauceLabs)
7382
// Also do it async to avoid blocking the main thread
7483
// Right now `SentryDispatchQueueWrapper.dispatchAsyncOnMainQueue` is not used because the SDK starts on the main thread,
@@ -125,7 +134,7 @@ public class SentryReachability: NSObject {
125134
currentConnectivity = .none
126135

127136
// Clean up NWPathMonitor
128-
if #available(iOS 12.0, macOS 10.14, tvOS 12.0, *) {
137+
if #available(iOS 12.0, macOS 10.14, tvOS 12.0, visionOS 1.0, watchOS 5.0, *) {
129138
if let monitor = pathMonitor as? NWPathMonitor {
130139
SentrySDKLog.debug("Stopping NWPathMonitor")
131140
monitor.cancel()
@@ -136,7 +145,7 @@ public class SentryReachability: NSObject {
136145
SentrySDKLog.debug("Cleaning up reachability queue.")
137146
}
138147

139-
@available(iOS 12.0, macOS 10.14, tvOS 12.0, *)
148+
@available(iOS 12.0, macOS 10.14, tvOS 12.0, visionOS 1.0, watchOS 5.0, *)
140149
private func pathUpdateHandler(_ path: NWPath) {
141150
SentrySDKLog.debug("SentryPathUpdateHandler called with path status: \(path.status)")
142151

@@ -151,7 +160,7 @@ public class SentryReachability: NSObject {
151160
connectivityCallback(connectivity)
152161
}
153162

154-
@available(iOS 12.0, macOS 10.14, tvOS 12.0, *)
163+
@available(iOS 12.0, macOS 10.14, tvOS 12.0, visionOS 1.0, watchOS 5.0, *)
155164
private func connectivityFromPath(_ path: NWPath) -> SentryConnectivity {
156165
guard path.status == .satisfied else {
157166
return .none
@@ -211,7 +220,7 @@ public class SentryReachability: NSObject {
211220

212221
// MARK: - Test utils
213222
#if DEBUG || SENTRY_TEST || SENTRY_TEST_CI
214-
@available(iOS 12.0, macOS 10.14, tvOS 12.0, *)
223+
@available(iOS 12.0, macOS 10.14, tvOS 12.0, visionOS 1.0, watchOS 5.0, *)
215224
extension SentryReachability {
216225
@objc public func setReachabilityIgnoreActualCallback(_ value: Bool) {
217226
SentrySDKLog.debug("Setting ignore actual callback to \(value)")
@@ -229,5 +238,3 @@ extension SentryReachability {
229238
}
230239
}
231240
#endif // DEBUG || SENTRY_TEST || SENTRY_TEST_CI
232-
233-
#endif // !os(watchOS) && !((swift(>=5.9) && os(visionOS)) && SENTRY_NO_UIKIT)

0 commit comments

Comments
 (0)