diff --git a/Sources/Sentry/SentryDependencyContainer.m b/Sources/Sentry/SentryDependencyContainer.m index e3c90660d75..8d639353b17 100644 --- a/Sources/Sentry/SentryDependencyContainer.m +++ b/Sources/Sentry/SentryDependencyContainer.m @@ -25,11 +25,14 @@ #if SENTRY_HAS_UIKIT # import "SentryFramesTracker.h" # import "SentryUIApplication.h" -# import "SentryUIDeviceWrapper.h" # import # import #endif // SENTRY_HAS_UIKIT +#if TARGET_OS_IOS +# import "SentryUIDeviceWrapper.h" +#endif // TARGET_OS_IOS + @implementation SentryDependencyContainer static SentryDependencyContainer *instance; @@ -154,7 +157,7 @@ - (SentryBinaryImageCache *)binaryImageCache return _binaryImageCache; } -#if SENTRY_HAS_UIKIT +#if TARGET_OS_IOS - (SentryUIDeviceWrapper *)uiDeviceWrapper { if (_uiDeviceWrapper == nil) { @@ -166,7 +169,9 @@ - (SentryUIDeviceWrapper *)uiDeviceWrapper } return _uiDeviceWrapper; } +#endif // TARGET_OS_IOS +#if SENTRY_HAS_UIKIT - (SentryScreenshot *)screenshot { if (_screenshot == nil) { diff --git a/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h b/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h index d181d586404..3506801d310 100644 --- a/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h +++ b/Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h @@ -25,9 +25,12 @@ @class SentryFramesTracker; @class SentryScreenshot; @class SentryUIApplication; -@class SentryUIDeviceWrapper; @class SentryViewHierarchy; -#endif +#endif // SENTRY_HAS_UIKIT + +#if TARGET_OS_IOS +@class SentryUIDeviceWrapper; +#endif // TARGET_OS_IOS NS_ASSUME_NONNULL_BEGIN @@ -63,8 +66,11 @@ SENTRY_NO_INIT @property (nonatomic, strong) SentryScreenshot *screenshot; @property (nonatomic, strong) SentryViewHierarchy *viewHierarchy; @property (nonatomic, strong) SentryUIApplication *application; +#endif // SENTRY_HAS_UIKIT + +#if TARGET_OS_IOS @property (nonatomic, strong) SentryUIDeviceWrapper *uiDeviceWrapper; -#endif +#endif // TARGET_OS_IOS - (SentryANRTracker *)getANRTracker:(NSTimeInterval)timeout; diff --git a/Tests/SentryTests/Helper/SentryExtraContextProviderTests.swift b/Tests/SentryTests/Helper/SentryExtraContextProviderTests.swift index 051e010ea64..502d3c3d51f 100644 --- a/Tests/SentryTests/Helper/SentryExtraContextProviderTests.swift +++ b/Tests/SentryTests/Helper/SentryExtraContextProviderTests.swift @@ -5,15 +5,15 @@ final class SentryExtraContextProviderTests: XCTestCase { private class Fixture { let crashWrapper = TestSentryCrashWrapper.sharedInstance() -#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) +#if os(iOS) || targetEnvironment(macCatalyst) let deviceWrapper = TestSentryUIDeviceWrapper() -#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) +#endif // os(iOS) || targetEnvironment(macCatalyst) let processWrapper = TestSentryNSProcessInfoWrapper() func getSut() -> SentryExtraContextProvider { - #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) + #if os(iOS) || targetEnvironment(macCatalyst) SentryDependencyContainer.sharedInstance().uiDeviceWrapper = deviceWrapper - #endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) + #endif // os(iOS) || targetEnvironment(macCatalyst) return SentryExtraContextProvider( crashWrapper: crashWrapper, processInfoWrapper: processWrapper) @@ -43,7 +43,7 @@ final class SentryExtraContextProviderTests: XCTestCase { } func testExtraDeviceInfo() { -#if os(iOS) +#if os(iOS) || targetEnvironment(macCatalyst) let sut = fixture.getSut() fixture.deviceWrapper.internalOrientation = .landscapeLeft fixture.deviceWrapper.internalBatteryState = .full @@ -55,7 +55,7 @@ final class SentryExtraContextProviderTests: XCTestCase { XCTAssertEqual(device?["orientation"] as? String, "landscape") XCTAssertEqual(device?["charging"] as? Bool, false) XCTAssertEqual(device?["battery_level"] as? UInt, 44) -#endif +#endif // os(iOS) || targetEnvironment(macCatalyst) } func testExtraProcessInfo() { diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index a2c4dacd004..44605b96c96 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -29,9 +29,9 @@ class SentryClientTest: XCTestCase { let trace = SentryTracer(transactionContext: TransactionContext(name: "SomeTransaction", operation: "SomeOperation"), hub: nil) let transaction: Transaction let crashWrapper = TestSentryCrashWrapper.sharedInstance() - #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) + #if os(iOS) || targetEnvironment(macCatalyst) let deviceWrapper = TestSentryUIDeviceWrapper() - #endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) + #endif // os(iOS) || targetEnvironment(macCatalyst) let processWrapper = TestSentryNSProcessInfoWrapper() let extraContentProvider: SentryExtraContextProvider let locale = Locale(identifier: "en_US") @@ -65,9 +65,9 @@ class SentryClientTest: XCTestCase { crashWrapper.internalAppMemorySize = 234_567 crashWrapper.internalFreeStorageSize = 345_678 - #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) + #if os(iOS) || targetEnvironment(macCatalyst) SentryDependencyContainer.sharedInstance().uiDeviceWrapper = deviceWrapper -#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) +#endif // os(iOS) || targetEnvironment(macCatalyst) extraContentProvider = SentryExtraContextProvider(crashWrapper: crashWrapper, processInfoWrapper: processWrapper) } @@ -714,7 +714,7 @@ class SentryClientTest: XCTestCase { } func testCaptureEvent_DeviceProperties_OtherValues() { -#if os(iOS) +#if os(iOS) || targetEnvironment(macCatalyst) fixture.deviceWrapper.internalOrientation = .landscapeLeft fixture.deviceWrapper.internalBatteryState = .full @@ -727,7 +727,7 @@ class SentryClientTest: XCTestCase { let charging = actual.context?["device"]?["charging"] as? Bool XCTAssertEqual(charging, false) } -#endif +#endif // os(iOS) || targetEnvironment(macCatalyst) } func testCaptureEvent_AddCurrentCulture() { diff --git a/Tests/SentryTests/SentryCrash/TestSentryUIDeviceWrapper.swift b/Tests/SentryTests/SentryCrash/TestSentryUIDeviceWrapper.swift index 5d4d726f1a6..e10b5f8d80f 100644 --- a/Tests/SentryTests/SentryCrash/TestSentryUIDeviceWrapper.swift +++ b/Tests/SentryTests/SentryCrash/TestSentryUIDeviceWrapper.swift @@ -1,6 +1,6 @@ import Sentry -#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) +#if os(iOS) || targetEnvironment(macCatalyst) class TestSentryUIDeviceWrapper: SentryUIDeviceWrapper { var internalOrientation = UIDeviceOrientation.portrait var internalIsBatteryMonitoringEnabled = true @@ -23,4 +23,4 @@ class TestSentryUIDeviceWrapper: SentryUIDeviceWrapper { return internalBatteryState } } -#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) +#endif // os(iOS) || targetEnvironment(macCatalyst)