-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CAT-274] NetworkTracking 모듈 및 마이페이지 오프라인 대응 (#48)
- Loading branch information
Showing
10 changed files
with
138 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
22 changes: 22 additions & 0 deletions
22
Projects/Domain/NetworkTracking/Interface/NetworkTrackingInterface.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,22 @@ | ||
// | ||
// NetworkTrackingInterface.swift | ||
// NetworkTracking | ||
// | ||
// Created by 김지현 on 8/21/24. | ||
// | ||
|
||
import Foundation | ||
import Network | ||
|
||
import Dependencies | ||
import DependenciesMacros | ||
|
||
@DependencyClient | ||
public struct NetworkTracking { | ||
public var updateNetworkConnected: @Sendable () -> AsyncStream<Bool> = { .never } | ||
} | ||
|
||
extension NetworkTracking: TestDependencyKey { | ||
public static let previewValue = Self() | ||
public static let testValue = Self() | ||
} |
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,20 @@ | ||
import ProjectDescription | ||
import ProjectDescriptionHelpers | ||
|
||
@_spi(Domain) | ||
@_spi(Core) | ||
import DependencyPlugin | ||
|
||
let project: Project = .makeTMABasedProject( | ||
module: Domain.NetworkTracking, | ||
scripts: [], | ||
targets: [ | ||
.sources, | ||
.interface | ||
], | ||
dependencies: [ | ||
.interface: [ | ||
.dependency(rootModule: Core.self) | ||
] | ||
] | ||
) |
41 changes: 41 additions & 0 deletions
41
Projects/Domain/NetworkTracking/Sources/NetworkTracking.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,41 @@ | ||
// | ||
// NetworkTracking.swift | ||
// NetworkTracking | ||
// | ||
// Created by 김지현 on 8/21/24. | ||
// | ||
|
||
import Foundation | ||
import Network | ||
|
||
import NetworkTrackingInterface | ||
|
||
import Dependencies | ||
|
||
extension NetworkTracking: DependencyKey { | ||
public static let liveValue: NetworkTracking = .live() | ||
|
||
public static func live() -> NetworkTracking { | ||
let networkMonitor = NWPathMonitor() | ||
let globalQueue = DispatchQueue.global() | ||
|
||
return NetworkTracking( | ||
updateNetworkConnected: { | ||
networkMonitor.start(queue: globalQueue) | ||
return AsyncStream<Bool> { continuation in | ||
let initialState = networkMonitor.currentPath.status == .satisfied ? true : false | ||
continuation.yield(initialState) | ||
|
||
networkMonitor.pathUpdateHandler = { path in | ||
let isConnected = path.status == .satisfied ? true : false | ||
continuation.yield(isConnected) | ||
} | ||
|
||
continuation.onTermination = { _ in | ||
networkMonitor.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
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