Skip to content

Commit

Permalink
ref: compile out more code not supported in watchOS
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Jul 15, 2023
1 parent 0fd25c8 commit 66ad62a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 26 deletions.
11 changes: 9 additions & 2 deletions Sources/Sentry/SentryHttpTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
#import "SentryNSURLRequest.h"
#import "SentryNSURLRequestBuilder.h"
#import "SentryOptions.h"
#import "SentryReachability.h"
#import "SentrySerialization.h"

#if !TARGET_OS_WATCH
# import "SentryReachability.h"
#endif // !TARGET_OS_WATCH

static NSTimeInterval const cachedEnvelopeSendDelay = 0.1;

@interface
Expand All @@ -33,7 +36,9 @@
@property (nonatomic, strong) SentryEnvelopeRateLimit *envelopeRateLimit;
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueue;
@property (nonatomic, strong) dispatch_group_t dispatchGroup;
#if !TARGET_OS_WATCH
@property (nonatomic, strong) SentryReachability *reachability;
#endif // !TARGET_OS_WATCH

#if TEST || TESTCI
@property (nullable, nonatomic, strong) void (^startFlushCallback)(void);
Expand Down Expand Up @@ -67,7 +72,9 @@ - (id)initWithOptions:(SentryOptions *)options
rateLimits:(id<SentryRateLimits>)rateLimits
envelopeRateLimit:(SentryEnvelopeRateLimit *)envelopeRateLimit
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
#if !TARGET_OS_WATCH
reachability:(SentryReachability *)reachability
#endif // !TARGET_OS_WATCH
{
if (self = [super init]) {
self.options = options;
Expand All @@ -83,11 +90,11 @@ - (id)initWithOptions:(SentryOptions *)options
self.discardedEvents = [NSMutableDictionary new];
[self.envelopeRateLimit setDelegate:self];
[self.fileManager setDelegate:self];
self.reachability = reachability;

[self sendAllCachedEnvelopes];

#if !TARGET_OS_WATCH
self.reachability = reachability;
__weak SentryHttpTransport *weakSelf = self;
[self.reachability monitorURL:[NSURL URLWithString:@"https://sentry.io"]
usingCallback:^(BOOL connected, NSString *_Nonnull typeDescription) {
Expand Down
8 changes: 2 additions & 6 deletions Sources/Sentry/SentryReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,8 @@
}
}

#endif

@implementation SentryReachability

#if !TARGET_OS_WATCH

+ (void)initialize
{
if (self == [SentryReachability class]) {
Expand Down Expand Up @@ -162,6 +158,6 @@ - (NSString *)keyForInstance
return [self description];
}

#endif

@end

#endif // !TARGET_OS_WATCH
11 changes: 9 additions & 2 deletions Sources/Sentry/SentryTransportFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
#import "SentryQueueableRequestManager.h"
#import "SentryRateLimitParser.h"
#import "SentryRateLimits.h"
#import "SentryReachability.h"

#import "SentryRetryAfterHeaderParser.h"
#import "SentryTransport.h"
#import <Foundation/Foundation.h>

#if !TARGET_OS_WATCH
# import "SentryReachability.h"
#endif // !TARGET_OS_WATCH

NS_ASSUME_NONNULL_BEGIN

@interface
Expand Down Expand Up @@ -58,7 +62,10 @@ @implementation SentryTransportFactory
rateLimits:rateLimits
envelopeRateLimit:envelopeRateLimit
dispatchQueueWrapper:dispatchQueueWrapper
reachability:[[SentryReachability alloc] init]];
#if !TARGET_OS_WATCH
reachability:[[SentryReachability alloc] init]
#endif // !TARGET_OS_WATCH
];
}

@end
Expand Down
11 changes: 9 additions & 2 deletions Sources/Sentry/include/SentryHttpTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#import "SentryTransport.h"
#import <Foundation/Foundation.h>

@class SentryOptions, SentryDispatchQueueWrapper, SentryNSURLRequestBuilder, SentryReachability;
@class SentryOptions, SentryDispatchQueueWrapper, SentryNSURLRequestBuilder;

#if !TARGET_OS_WATCH
@class SentryReachability;
#endif // !TARGET_OS_WATCH

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -21,7 +25,10 @@ SENTRY_NO_INIT
rateLimits:(id<SentryRateLimits>)rateLimits
envelopeRateLimit:(SentryEnvelopeRateLimit *)envelopeRateLimit
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
reachability:(SentryReachability *)reachability;
#if !TARGET_OS_WATCH
reachability:(SentryReachability *)reachability
#endif // !TARGET_OS_WATCH
;

@end

Expand Down
9 changes: 2 additions & 7 deletions Sources/Sentry/include/SentryReachability.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ NSString *SentryConnectivityFlagRepresentation(SCNetworkReachabilityFlags flags)

BOOL SentryConnectivityShouldReportChange(SCNetworkReachabilityFlags flags);

#endif

/**
* Function signature to connectivity monitoring callback of @c SentryReachability
* @param connected @c YES if the monitored URL is reachable
Expand All @@ -53,7 +51,6 @@ typedef void (^SentryConnectivityChangeBlock)(BOOL connected, NSString *typeDesc
*/
@interface SentryReachability : NSObject

#if !TARGET_OS_WATCH
/**
* Invoke a block each time network connectivity changes
* @param URL The URL monitored for changes. Should be equivalent to
Expand All @@ -69,10 +66,8 @@ typedef void (^SentryConnectivityChangeBlock)(BOOL connected, NSString *typeDesc

- (NSString *)keyForInstance;

#endif

@end

#if !TARGET_OS_WATCH
NS_ASSUME_NONNULL_END
#endif

#endif // !TARGET_OS_WATCH
21 changes: 20 additions & 1 deletion Tests/SentryTests/Networking/SentryHttpTransportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class SentryHttpTransportTests: XCTestCase {
dqw.dispatchAfterExecutesBlock = true
return dqw
}()

#if !os(watchOS)
let reachability = TestSentryReachability()
#endif // !os(watchOS)

let flushTimeout: TimeInterval = 0.5

let userFeedback: UserFeedback
Expand Down Expand Up @@ -99,6 +103,7 @@ class SentryHttpTransportTests: XCTestCase {
}

var sut: SentryHttpTransport {
#if !os(watchOS)
return SentryHttpTransport(
options: options,
fileManager: fileManager,
Expand All @@ -108,7 +113,19 @@ class SentryHttpTransportTests: XCTestCase {
envelopeRateLimit: EnvelopeRateLimit(rateLimits: rateLimits),
dispatchQueueWrapper: dispatchQueueWrapper,
reachability: reachability
)
)

#else // os(watchOS)
return SentryHttpTransport(
options: options,
fileManager: fileManager,
requestManager: requestManager,
requestBuilder: requestBuilder,
rateLimits: rateLimits,
envelopeRateLimit: EnvelopeRateLimit(rateLimits: rateLimits),
dispatchQueueWrapper: dispatchQueueWrapper
)
#endif // !os(watchOS)
}
}

Expand Down Expand Up @@ -778,6 +795,7 @@ class SentryHttpTransportTests: XCTestCase {
setTestDefaultLogLevel()
}

#if !os(watchOS)
func testSendsWhenNetworkComesBack() {
givenNoInternetConnection()

Expand All @@ -803,6 +821,7 @@ class SentryHttpTransportTests: XCTestCase {

fixture.reachability.triggerNetworkReachable()
}
#endif // !os(watchOS)

private func givenRetryAfterResponse() -> HTTPURLResponse {
let response = TestResponseFactory.createRetryAfterResponse(headerValue: "1")
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/Networking/SentryReachabilityTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ - (void)testUniqueKeyForInstances
}

@end
#endif
#endif // !TARGET_OS_WATCH
4 changes: 4 additions & 0 deletions Tests/SentryTests/Networking/TestSentryReachability.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if !os(watchOS)

import SentryTestUtils

class TestSentryReachability: SentryReachability {
Expand All @@ -16,3 +18,5 @@ class TestSentryReachability: SentryReachability {
stopMonitoringInvocations.record(Void())
}
}

#endif // !os(watchOS)
9 changes: 4 additions & 5 deletions Tests/SentryTests/SentryTests-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Use this file to import your target's public headers that you would like to
// expose to Swift.
//
#if !TARGET_OS_WATCH
# import "SentryReachability.h"
#endif // !TARGET_OS_WATCH

#import "NSData+Sentry.h"
#import "NSData+SentryCompression.h"
#import "NSDate+SentryExtras.h"
Expand Down Expand Up @@ -132,7 +132,6 @@
#import "SentryRandom.h"
#import "SentryRateLimitParser.h"
#import "SentryRateLimits.h"
#import "SentryReachability.h"
#import "SentryRetryAfterHeaderParser.h"
#import "SentrySDK+Private.h"
#import "SentrySDK+Tests.h"
Expand Down

0 comments on commit 66ad62a

Please sign in to comment.