2017-05-29 10 views
0

家庭用アプリケーションでは、アクセサリを追加しようとすると以下の警告が表示されます。iOS:ホームキット - デバイスでBluetooth&WiFiサービスを有効にするかどうかを検出する方法は?

また、アプリケーションでHomeKitフレームワークを使用していて、ユーザーがアクセサリを追加しようとしたときに警告を表示したいとします。

私はのアプリで同じ警告を表示するためにどのような変更を行う必要がありますか? iOS版ではBluetoothのために

Screenshot of Home App

+0

ます。https:/ - :https://github.com/ashleymills/Reachability.swift

ソースの回答:以下のコードは、ビーコンマネージャ

//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に見てみるためである私のプロジェクトから抽出されます/stackoverflow.com/a/21696963/4417447 Wifiサービスの場合:https://stackoverflow.com/a/29487450/4417447 – santak

答えて

0

、あなたは(CoreBluetooth Frameworkの)CBPeripheralManagerを持っています。 Bluetooth接続を確認するには、あなたのクラスがCBPeripheralManagerのデリゲートとして宣言し、ローカル変数を作成:その後、

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

を、あなたのクラスには、お使いのBluetoothを有効または無効にされたときに気づいた取得するコールバックを実装する必要があります。 Bluetooth対応のためにDetecting if Wifi or Bluetooth is turned on or off by the user

関連する問題