当前位置:网站首页>Swift extension networkutil (network monitoring) (source code)
Swift extension networkutil (network monitoring) (source code)
2022-06-24 08:05:00 【Fenghanxu】
I always feel that what I write is not technology , But feelings , One tutorial after another is the trace of one's own journey . Success with expertise is the most replicable , I hope my path will make you less detours , I hope I can help you erase the dust of knowledge , I hope I can help you clarify the context of knowledge , I hope there will be you and me on the top of technology in the future .
(Swift)NetworkUtil Monitor the network
Preface
2022.06.23 Today I wrote a ios13 And above monitor network encapsulation . You can get the current network status , When the network changes, you will be notified
On the subject
It is very convenient to use
1. Enable network monitoring when starting 
2. Then you can use it wherever you want 
import UIKit
import SnapKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// Get the enumeration of network status
print("connectType: \(NetworkUtil.shared.connectType.rawValue)")
// Get the text value of the network status
print("readableConnectType: \(NetworkUtil.shared.readableConnectType)")
// Register for network monitoring
NotificationCenter.default.addObserver(
self,
selector: #selector(onNetworkChange),
name: Notification.Name("onNetworkChange"),
object: nil
)
}
// Once the network changes, it will be notified
@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(" No network available at present ")
default:
break
}
}
}
}
边栏推荐
- 闲谈:3AC到底发生了什么?
- Common array encapsulation
- Hongmeng development IV
- Part 2: drawing a window
- The monthly salary of two years after graduation is 36K. It's not difficult to say
- Latest news of awtk: new usage of grid control
- Auto usage example
- 力扣(LeetCode)174. 地下城游戏(2022.06.23)
- .jar中没有主清单属性
- Jenkins 太老了 试试它?云原生 CI/CD Tekton
猜你喜欢

uniapp uni-app H5 端如何取消 返回按钮的显示 autoBackButton不生效

Latest news of awtk: new usage of grid control

【资料上新】迅为基于3568开发板的NPU开发资料全面升级

第 2 篇:繪制一個窗口

The monthly salary of two years after graduation is 36K. It's not difficult to say

软件工程导论——第二章——可行性研究

保留一位小数和保留两位小数

首次曝光 唯一全域最高等级背后的阿里云云原生安全全景图

Chapter 3: drawing triangles

某问答社区App x-zse-96签名分析
随机推荐
站在风暴中心:如何给飞奔中的腾讯更换引擎
从 jsonpath 和 xpath 到 SPL
语料库数据处理个案实例(读取多个文本文件、读取一个文件夹下面指定的多个文件、解码错误、读取多个子文件夹文本、多个文件批量改名)
Using kubeconfig files to organize cluster access
Opencvsharp binary image anti color
On the H5 page, the Apple phone blocks the content when using fixed to locate the bottom of the tabbar
一文理解同步FIFO
4-操作列表(循环结构)
力扣(LeetCode)174. 地下城游戏(2022.06.23)
Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
Leetcode exercise - jumping game, combination summation
Resolution error: LNK2019 unresolved external symbol
第 2 篇:绘制一个窗口
Swift Extension NetworkUtil(网络监听)(源码)
Leetcode 207: course schedule (topological sorting determines whether the loop is formed)
Any remarks
[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA
Jenkins is too old try it? Cloud native ci/cd Tekton
Chapter 4 line operation of canvas
交友相亲类软件是如何割你韭菜的