์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- combine
- node.js
- RxSwift
- designpattern
- swift
- BOJ
- BFS
- Lv2
- rxcocoa
- arkit
- Flutter
- reactorkit
- Xcode
- CollectionView
- SnapKit
- MVVM
- tableView
- ํจ์คํธ์บ ํผ์ค
- ํ๋ก๊ทธ๋๋จธ์ค
- SwiftUI
- ๋ฐฑ์ค
- realm
- XCTest
- raywenderlich
- UIKit
- Swfit
- ios
- Kuring
- visionOS
- TCA
Archives
- Today
- Total
lgvv98
[iOS15] Device์ ๋คํธ์ํฌ ์ฐ๊ฒฐ์ฌ๋ถ ํ์ธ ๐ก ๋ณธ๋ฌธ
โ ๏ธ deprecated โ ๏ธ/๐ท ์ฝ๋ก๋19์๋ฆผ์ฑ
[iOS15] Device์ ๋คํธ์ํฌ ์ฐ๊ฒฐ์ฌ๋ถ ํ์ธ ๐ก
๐ฅ ์บ๋ฟ๋งจ 2021. 11. 5. 00:28โ ์ด๋ฒ ์๊ฐ์๋ Device์ ๋คํธ์ํฌ ์ฐ๊ฒฐ ์ํ๋ฅผ ํ์ธํ๋ ์ฝ๋์ ๋ํด์ ์์๋ณผ ์์ ์ด์ผ.
๋ด๊ฐ ๋ง๋ ์ฑ์ ํต์ฌ ๊ธฐ๋ฅ์ API ํต์ ์ ํ์์ ์ผ๋ก ํด์ผํ๋ค๋ ๊ฒ์ด์์ด.
๊ทธ! ๋! ์!
โ DeviceManager
//
// DeviceConfig.swift
// Covid19AlarmApp
//
// Created by Hamlit Jason on 2021/08/01.
//
import Foundation
import SystemConfiguration
class DeviceManager {
static let shared : DeviceManager = DeviceManager()
var networkStatue : Bool {
get {
return checkDeviceNetworkStatus()
}
}
private init() {
}
private func checkDeviceNetworkStatus() -> Bool {
print("Check to Device Natwork Status....")
var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in
SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)
}
}
var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)
if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false {
return false
}
// Working for Cellular and WIFI
let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
let ret = (isReachable && !needsConnection)
return ret
}
}
์์ ์ฝ๋๋ ๋คํธ์ํฌ ์ํ๋ฅผ ํ์ธํ๊ธฐ ์ํ DeviceManager ํด๋์ค์ผ
โ ์์ DeviceManager๋ฅผ ๋ฐํ์ผ๋ก ๋ง๋ ํจ์
func checkDeviceNetworkStatus() {
if !(DeviceManager.shared.networkStatue) {
let alert: UIAlertController = UIAlertController(title: "๋คํธ์ํฌ ์ํ ํ์ธ", message: "๋คํธ์ํฌ๊ฐ ๋ถ์์ ํฉ๋๋ค.", preferredStyle: .alert)
let action: UIAlertAction = UIAlertAction(title: "๋ค์ ์๋", style: .default, handler: { (action) in
self.checkDeviceNetworkStatus()
})
alert.addAction(action)
present(alert, animated: true, completion: nil)
} else {
// ๋คํธ์ํฌ ์ํ๊ฐ ์ ์์ ์ผ๋ก ์๋ํ๊ณ ์์ ์
// do Something...
}
}
์ด๋ ๊ฒ ํจ์๋ฅผ ๋ง๋ค์ด์ ์ฌ์ฉํ ์ ์์ด.
'โ ๏ธ deprecated โ ๏ธ > ๐ท ์ฝ๋ก๋19์๋ฆผ์ฑ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS] ์ฑ ์ด๋ฆ ๋ณ๊ฒฝํ๊ธฐ โ (0) | 2021.11.09 |
---|---|
[README.md] Covid19AlarmApp ๐ฆ (0) | 2021.11.09 |
[iOS14] Swift5 alertDialog ํจ์๋ก ๋ง๋ค์ด ์ฌ์ฉํ๊ธฐ (0) | 2021.08.04 |
[iOS14] โ๏ธ SplashView๋ฅผ ํ์ฉํด Alert ๋ฐ์ํ๊ธฐ (0) | 2021.08.02 |
[iOS14] ๋ฐฑ๊ทธ๋ผ์ด๋์์ ํน์ ์๊ฐ ๋ก์ปฌ ์๋ฆผ๋ณด๋ด๊ธฐโฐ (0) | 2021.07.29 |
Comments