当前位置:网站首页>Écouter le réseau d'extension SWIFT (source)
Écouter le réseau d'extension SWIFT (source)
2022-06-24 08:05:00 【Feng hanxu】
J'ai toujours pensé que je n'écrivais pas sur la technologie,C'est un sentiment.,Les tutoriels individuels sont des traces de leur propre chemin.Le succès professionnel est le plus reproductible,J'espère que mon chemin vous permettra d'éviter les détours,J'espère pouvoir vous aider à effacer la poussière de la connaissance,J'espère pouvoir vous aider à comprendre le contexte de la connaissance,J'espère que vous et moi serons au Sommet de la technologie du futur.
(Swift)NetworkUtilSurveillance du réseau
Préface
2022.06.23J'ai écrit aujourd'huiios13Et au - dessus de l'encapsulation du réseau d'écoute.Vous pouvez obtenir l'état actuel du réseau,Le réseau est informé dès qu'il change
C'est vrai.
Très pratique à utiliser
1.Activer l'écoute réseau au démarrage
2.Et puis on peut l'utiliser là où on veut
import UIKit
import SnapKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// Obtenir le jus d'énumération pour l'état du réseau
print("connectType: \(NetworkUtil.shared.connectType.rawValue)")
// Obtenir la valeur textuelle de l'état du réseau
print("readableConnectType: \(NetworkUtil.shared.readableConnectType)")
//Enregistrer l'écoute du réseau
NotificationCenter.default.addObserver(
self,
selector: #selector(onNetworkChange),
name: Notification.Name("onNetworkChange"),
object: nil
)
}
// Le réseau est informé de tout changement
@objc func onNetworkChange(notification : Notification){
DispatchQueue.main.async {
guard
let dictionary = notification.userInfo,
let type = dictionary["type"] as? Int
else {
return
}
let connectType = NetworkUtil.ConnectType(rawValue: type)!
switch (connectType) {
case .unknown:
print(" Aucun réseau disponible actuellement ")
default:
break
}
}
}
}
边栏推荐
- UTC、GMT、CST
- Ke Yi fallible point
- 用Ngrok 配置属于自己的免费外网域名
- Vulnhub靶机:BOREDHACKERBLOG: SOCIAL NETWORK
- 从 jsonpath 和 xpath 到 SPL
- [008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA
- Notes on the use of date and time base
- 运行npm run eject报错解决方法
- Chapter 2 line graph of canvas
- L1-019 who goes first (15 points)
猜你喜欢

单片机STM32F103RB,BLDC直流电机控制器设计,原理图、源码和电路方案

Oracle advanced SQL qualified query

Screenshot recommendation - snipaste

Latest news of awtk: new usage of grid control

本地备份和还原 SQL Server 数据库

语料库数据处理个案实例(读取多个文本文件、读取一个文件夹下面指定的多个文件、解码错误、读取多个子文件夹文本、多个文件批量改名)

JDBC 在性能测试中的应用

Graphmae ---- quick reading of papers

Exness: Powell insisted on his anti inflation commitment and pointed out that recession is possible

模型效果优化,试一下多种交叉验证的方法(系统实操)
随机推荐
解决错误: LNK2019 无法解析的外部符号
L1-019 谁先倒 (15 分)
Serialization of unity
Mousse shares listed on Shenzhen Stock Exchange: gross profit margin continued to decline, and marketing failed in the first quarter of 2022
解决 These dependencies were not found: * core-js/modules/es6.array.fill in xxx 之类的问题
Opencvsharp binary image anti color
You get in Anaconda
Latest news of awtk: new usage of grid control
使用 kubeconfig 文件组织集群访问
What kind of experience is it when the Institute earns 20000 yuan a month!
Phonics
IndexError: Target 7 is out of bounds.
Thread blocking
Smart pointer remarks
Pair class notes
Review of postgraduate English final exam
Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved
GraphMAE----论文快速阅读
Oracle-高级SQL限定查询