Music_Player3/MusicPlayer/MP/Common/Tool(工具封装)/MPNetWorkManager.swift
Mr.zhou 96147c5e37 项目:Musicoo
版本:A面 1.0
构建:1.1
更新内容:对项目A面功能的实现,经测试确定各项功能无问题。
更新时间:2024年4月12日 11:20
上传状态:已上传App Connect
2024-04-12 11:19:58 +08:00

58 lines
2.2 KiB
Swift

//
// MPNetWorkManager.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/4/11.
//
import UIKit
import Network
///
class MPNetWorkManager: NSObject {
//
static let shared = MPNetWorkManager()
//
private override init() {
super.init()
}
///
func requestNetworkPermission(oberve:UIViewController, completeHanlder:ActionBlock?) {
let monitor = NWPathMonitor()
monitor.pathUpdateHandler = { path in
switch path.status {
case .satisfied:
DispatchQueue.main.async {
guard completeHanlder != nil else {
return
}
completeHanlder!()
}
default://
DispatchQueue.main.async {
//
let alertController = UIAlertController(title: "Access network request", message: "”Musicoo“ needs to be loaded via a network request. Please click “Settings” to allow this application to gain access to the network.", preferredStyle: .alert)
let CancelAction = UIAlertAction(title:"Cancel", style: .cancel) { (Cancel) in
}
let OKAction = UIAlertAction(title: "Settings", style: .default) { (action) in
let url = URL(string: UIApplication.openSettingsURLString)
if let url = url,UIApplication.shared.canOpenURL(url){
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:]) { (success) in
}
}else{
UIApplication.shared.canOpenURL(url)
}
}
}
alertController.addAction(CancelAction)
alertController.addAction(OKAction)
oberve.present(alertController, animated: true, completion: nil)
}
}
}
let queue = DispatchQueue(label: "MPNetWorkManager")
monitor.start(queue: queue)
}
}