-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Sources/Amplitude/Plugins/NetworkConnectivityCheckerPlugin.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// NetworkConnectivityCheckerPlugin.swift | ||
// Amplitude-Swift | ||
// | ||
// Created by Xinyi.Ye on 1/26/24. | ||
// | ||
|
||
import Foundation | ||
import Network | ||
|
||
open class NetworkConnectivityCheckerPlugin: BeforePlugin { | ||
public static let Disabled: Bool? = nil | ||
let monitor = NWPathMonitor() | ||
|
||
|
||
open override func setup(amplitude: Amplitude) { | ||
super.setup(amplitude: amplitude) | ||
self.amplitude?.logger?.debug(message: "Installing AndroidNetworkConnectivityPlugin, offline feature should be supported.") | ||
|
||
// Define handler for network changes | ||
monitor.pathUpdateHandler = { path in | ||
if path.status == .satisfied { | ||
self.amplitude?.logger?.debug(message: "Network connectivity changed to online.") | ||
self.amplitude?.configuration.offline = false | ||
} else { | ||
self.amplitude?.logger?.debug(message: "Network connectivity changed to offline.") | ||
self.amplitude?.configuration.offline = true | ||
} | ||
} | ||
|
||
// Start network monitor | ||
let queue = DispatchQueue(label: "networkConnectivityChecker.amplitude.com") | ||
monitor.start(queue: queue) | ||
} | ||
|
||
open override func teardown() { | ||
monitor.cancel() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters