当前位置:网站首页>É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
}
}
}
}
边栏推荐
- Graphmae - - lecture rapide des documents
- 用Ngrok 配置属于自己的免费外网域名
- Part 2: drawing a window
- 不止于观测|阿里云可观测套件正式发布
- 10. Tencent cloud IOT device side learning - firmware upgrade
- Vulnhub target: boredhackerblog_ CLOUD AV
- Synchronous FIFO
- Any remarks
- Case examples of corpus data processing (cases related to sentence retrieval)
- L1-019 谁先倒 (15 分)
猜你喜欢

语料库数据处理个案实例(句子检索相关个案)

关于h5页面苹果手机使用fixed定位tabbar最底部时遮挡内容问题

First acquaintance with JUC - day01

Graphmae - - lecture rapide des documents

Latest news of awtk: new usage of grid control

Baidu map, coordinate inversion, picking coordinate position

Resolution error: LNK2019 unresolved external symbol

Signature analysis of app x-zse-96 in a Q & a community

Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
![[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA](/img/a0/f03b8d9c8f5e53078c38cce11f8ad3.png)
[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA
随机推荐
Svn actual measurement common operation record operation
What kind of experience is it when the Institute earns 20000 yuan a month!
L1-019 谁先倒 (15 分)
Solution to the error of running NPM run eject
From jsonpath and XPath to spl
Thread support
快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
Swift Extension NetworkUtil(网络监听)(源码)
Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
Smart pointer remarks
本地备份和还原 SQL Server 数据库
Redolog and binlog
ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved
Jenkins is too old try it? Cloud native ci/cd Tekton
Mousse shares listed on Shenzhen Stock Exchange: gross profit margin continued to decline, and marketing failed in the first quarter of 2022
GraphMAE----论文快速阅读
Duilib display memory picture
力扣(LeetCode)174. 地下城游戏(2022.06.23)
Synchronous FIFO
1-4metasploitable2介绍