From 853e4e510a1c1c098f9404ef6ef4e1281c5298f4 Mon Sep 17 00:00:00 2001 From: Chris Leonavicius Date: Tue, 4 Jun 2024 11:27:15 -0700 Subject: [PATCH] fix: Disable network connectivity check on watchOS as it is not supported on real devices (#174) --- Sources/Amplitude/Amplitude.swift | 3 ++- Sources/Amplitude/Plugins/Vendors/AppUtil.swift | 6 ++++++ Sources/Amplitude/Plugins/Vendors/VendorSystem.swift | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/Amplitude/Amplitude.swift b/Sources/Amplitude/Amplitude.swift index 5aa3e769..62667d8e 100644 --- a/Sources/Amplitude/Amplitude.swift +++ b/Sources/Amplitude/Amplitude.swift @@ -55,7 +55,8 @@ public class Amplitude { state.userId = userId } - if self.configuration.offline != NetworkConnectivityCheckerPlugin.Disabled { + if configuration.offline != NetworkConnectivityCheckerPlugin.Disabled, + VendorSystem.current.networkConnectivityCheckingEnabled { _ = add(plugin: NetworkConnectivityCheckerPlugin()) } // required plugin for specific platform, only has lifecyclePlugin now diff --git a/Sources/Amplitude/Plugins/Vendors/AppUtil.swift b/Sources/Amplitude/Plugins/Vendors/AppUtil.swift index 4356f310..d37cd906 100644 --- a/Sources/Amplitude/Plugins/Vendors/AppUtil.swift +++ b/Sources/Amplitude/Plugins/Vendors/AppUtil.swift @@ -245,6 +245,12 @@ import Foundation override var requiredPlugin: Plugin { return WatchOSLifecycleMonitor() } + + // Per https://developer.apple.com/documentation/technotes/tn3135-low-level-networking-on-watchos, + // NWPathMonitor is not supported on most WatchOS apps when running on a real device. + override var networkConnectivityCheckingEnabled: Bool { + return false + } } #endif diff --git a/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift b/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift index 9a30a4ab..758995c3 100644 --- a/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift +++ b/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift @@ -48,6 +48,10 @@ internal class VendorSystem { return nil } + var networkConnectivityCheckingEnabled: Bool { + return true + } + func beginBackgroundTask() -> BackgroundTaskCompletionCallback? { return nil }