GhostClock
V2EX  ›  iOS

[1024 还在加班] iOS 怎么判断设备的 WiFi 开关是否打开?

  •  
  •   GhostClock · Oct 24, 2015 · 3464 views
    This topic created in 3857 days ago, the information mentioned may be changed or developed.

    由于客户的某些 SB 要求,偏要监控设备的 WiFi 的开关是否打开,我 Google 了大半圈,硬是没有找到,难道只能监控网络的状态,不能监控 WiFi 开关是否打开吗?求解答……

    http://segmentfault.com/q/1010000003901530

    8 replies    2015-10-25 13:36:19 +08:00
    rayps
        1
    rayps  
       Oct 24, 2015
    func getSSID() -> String {

    let interfaces = CNCopySupportedInterfaces()
    if interfaces == nil {
    return "WiFi Not Found"
    // Simulator
    }

    let interfacesArray = interfaces.takeRetainedValue() as! [String]
    if interfacesArray.count <= 0 {
    return "Error"
    }

    let interfaceName = interfacesArray[0] as String
    let unsafeInterfaceData = CNCopyCurrentNetworkInfo(interfaceName)
    if unsafeInterfaceData == nil {
    return "No WiFi Connected"
    // 4G
    }

    let interfaceData = unsafeInterfaceData.takeRetainedValue() as Dictionary!

    return interfaceData["SSID"] as! String

    }


    这是我在 TodayWiFi 里的代码,忘了是哪个答案里找来的了
    rayps
        2
    rayps  
       Oct 24, 2015
    现在可能得要换成 Swift 2 的语法
    sunjourney
        3
    sunjourney  
       Oct 24, 2015 via iPhone
    这样就骂客户了?
    shierji
        4
    shierji  
       Oct 24, 2015
    这个要求感觉不算过分。。。
    crayygy
        5
    crayygy  
       Oct 24, 2015
    这个要求为啥要骂客户。。。(心疼 lz
    konakona
        6
    konakona  
       Oct 25, 2015
    这个要求合情合理....
    GhostClock
        7
    GhostClock  
    OP
       Oct 25, 2015
    @rayps 没看懂呀,哥 Orz
    GhostClock
        8
    GhostClock  
    OP
       Oct 25, 2015
    @sunjourney
    @shierji
    @crayygy
    @konakona
    光着这个当然合情合理,但是还有别的呀
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2824 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 143ms · UTC 15:29 · PVG 23:29 · LAX 08:29 · JFK 11:29
    ♥ Do have faith in what you're doing.