How to detect if the internet connection is over WiFi or Ethernet?

前端 未结 3 1401
旧时难觅i
旧时难觅i 2021-02-09 00:50

Is there a way to open network settings programmatically? Closest thing I know is opening the main settings page:

let settingsURL = NSURL(string: UIApplicationOp         


        
3条回答
  •  佛祖请我去吃肉
    2021-02-09 01:28

    You can use Reachability API.

    let reachability: Reachability = Reachability.reachabilityForInternetConnection()
    (reachability.currentReachabilityStatus().value == ReachableViaWiFi.value) // For WiFi
    (reachability.currentReachabilityStatus().value == ReachableViaWWAN.value) // For WWAN
    (reachability.currentReachabilityStatus().value == NotReachable.value) // For No Internet
    

提交回复
热议问题