V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
GhostClock
V2EX  ›  iOS

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

  •  
  •   GhostClock · 2015-10-24 16:20:00 +08:00 · 2626 次点击
    这是一个创建于 3113 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    http://segmentfault.com/q/1010000003901530

    8 条回复    2015-10-25 13:36:19 +08:00
    rayps
        1
    rayps  
       2015-10-24 16:42:45 +08:00
    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  
       2015-10-24 16:44:56 +08:00
    现在可能得要换成 Swift 2 的语法
    sunjourney
        3
    sunjourney  
       2015-10-24 17:21:39 +08:00 via iPhone
    这样就骂客户了?
    shierji
        4
    shierji  
       2015-10-24 19:46:40 +08:00
    这个要求感觉不算过分。。。
    crayygy
        5
    crayygy  
       2015-10-24 20:04:28 +08:00
    这个要求为啥要骂客户。。。(心疼 lz
    konakona
        6
    konakona  
       2015-10-25 11:48:49 +08:00
    这个要求合情合理....
    GhostClock
        7
    GhostClock  
    OP
       2015-10-25 13:34:46 +08:00
    @rayps 没看懂呀,哥 Orz
    GhostClock
        8
    GhostClock  
    OP
       2015-10-25 13:36:19 +08:00
    @sunjourney
    @shierji
    @crayygy
    @konakona
    光着这个当然合情合理,但是还有别的呀
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2215 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:58 · PVG 17:58 · LAX 02:58 · JFK 05:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.