Reachability Swift问题......无法在通知上调用方法

时间:2018-01-26 14:16:24

标签: ios swift appdelegate reachability reachability-swift

我正在尝试为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

0 个答案:

没有答案