2017-05-29 102 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

相關問題