我正在尝试为 ReachabilitySwift https://github.com/ashleymills/Reachability.swift/tree/master集成应用级通知
因此,当我将选择器设置为 #selector(reachabilityChanged(_:)) 时说存在“使用未解析的标识符”但我在 AppDelegate 类中拥有该功能.....所以我有点困惑.
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
struct Constants {
public static let googleApi = "xxx"
}
let centralreachability = Reachability()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged(_:)), name: .reachabilityChanged, object: centralreachability)
do{
try centralreachability?.startNotifier()
}
catch{
print("could not start reachability notifier")
}
NetworkActivityIndicatorManager.shared.isEnabled = true
return true
}
func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
switch reachability.connection {
case .wifi:
print("Reachable via WiFi")
case .cellular:
print("Reachable via Cellular")
case .none:
print("Network not reachable")
}
}
.....rest of AppDelegate