2017-05-29 127 views
0

当我们尝试添加附件时,家庭应用程序显示以下警报。iOS:Homekit - 如何检测设备中是否启用了蓝牙和WiFi服务?

我还在我的应用程序中使用了HomeKit framwork,并希望在用户尝试添加附件时显示警报。

我需要做什么样的更改在应用程序中显示相同的警报?

Screenshot of Home App

+0

对于蓝牙:HTTPS:/ /stackoverflow.com/a/21696963/4417447对于Wifi服务:https://stackoverflow.com/a/29487450/4417447 – santak

回答

0

对于蓝牙在iOS中,你有CBPeripheralManager(在CoreBluetooth框架)。要检查蓝牙连接,声明类为代表的CBPeripheralManager然后创建一个局部变量:

var myBTManager = CBPeripheralManager(delegate: self, queue: nil, options: nil) 

然后,当你的蓝牙启用或禁用您的类必须实现回调得到注意。下面是从我的项目中提取的代码是灯塔经理

//BT Manager 
func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager!) { 
    println(__FUNCTION__) 
    if peripheral.state == CBPeripheralManagerState.PoweredOn { 
     println("Broadcasting...") 
     //start broadcasting 
     myBTManager!.startAdvertising(_broadcastBeaconDict) 
    } else if peripheral.state == CBPeripheralManagerState.PoweredOff { 
     println("Stopped") 
     myBTManager!.stopAdvertising() 
    } else if peripheral.state == CBPeripheralManagerState.Unsupported { 
     println("Unsupported") 
    } else if peripheral.state == CBPeripheralManagerState.Unauthorized { 
     println("This option is not allowed by your application") 
    } 
} 

而对于WIFI,看看这个Github上:https://github.com/ashleymills/Reachability.swift

来源答: - Detecting if Wifi or Bluetooth is turned on or off by the user