Skip to content

Commit

Permalink
fix: Disable network connectivity check on watchOS as it is not suppo…
Browse files Browse the repository at this point in the history
…rted on real devices (#174)
  • Loading branch information
crleona committed Jun 4, 2024
1 parent 0d23d94 commit 853e4e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/Amplitude/Amplitude.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Sources/Amplitude/Plugins/Vendors/AppUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Sources/Amplitude/Plugins/Vendors/VendorSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ internal class VendorSystem {
return nil
}

var networkConnectivityCheckingEnabled: Bool {
return true
}

func beginBackgroundTask() -> BackgroundTaskCompletionCallback? {
return nil
}
Expand Down

0 comments on commit 853e4e5

Please sign in to comment.