xcode8.0で周囲のbluetoothのUUID情報をtableviewに表示したいのですが、BluetoothのUUID情報は受信できているのですが、tableviewに表示させることができません。コードは以下の様に書いています。
import UIKit import CoreBluetooth class ViewController: UIViewController, UITableViewDelegate, CBCentralManagerDelegate, UITableViewDataSource { var centralManager: CBCentralManager! var peripherals:[CBPeripheral] = [] var manager:CBCentralManager? = nil //var myUuids:NSMutableArray = NSMutableArray() var myUuids:[String] = [] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.centralManager = CBCentralManager(delegate: self, queue: nil, options: nil) } // ボタン押しでCoreBluetoothを起動させる @IBAction func scanButton(_ sender: AnyObject) { self.centralManager = CBCentralManager(delegate: self, queue: nil, options: nil) myUuids = [] } // centralManagerの状態を受信 func centralManagerDidUpdateState(_ central: CBCentralManager) { print(central.state) switch central.state { case .poweredOff: print("BLE Powered OFF") case .poweredOn: print("BLE Powered ON") central.scanForPeripherals(withServices: nil, options: nil) case .resetting: print("BLE Resetting") case .unauthorized: print("BEL Not Authorized") case .unknown: print("Unknow BLE") default: print("not supported") } } // peripheral 検索結果の受信 func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { if(!peripherals.contains(peripheral)) { //peripherals.append(peripheral) myUuids.append(peripheral.identifier.uuidString) print("RSSI: \(RSSI)") print("myUuids: \(myUuids)") //print("myUuids_count: \(myUuids.count)") } print("Peripheral(UUID): \(peripheral.identifier)") //print("Peripherals: \(peripherals)") } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { print("myUuids_count: \(myUuids.count)") return myUuids.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) cell.textLabel?.text = "\(myUuids[indexPath.row])" return cell } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
また、その他の設定はこのスクリーンショットの様にしています。
この結果、以下の様にUUID等得ることはできているのですが、tableviewには何も表示されません。
2016-10-14 09:13:13.391052 BLE_tableView[7654:2308859] [CoreBluetooth] XPC connection invalid CBManagerState BLE Powered ON RSSI: -55 myUuids: ( "7D7D584A-F9E0-44E6-AF1D-9117E5F79697" ) myUuids_count: 1 Peripheral(UUID): 7D7D584A-F9E0-44E6-AF1D-9117E5F79697 RSSI: -72 myUuids: ( "7D7D584A-F9E0-44E6-AF1D-9117E5F79697", "7D7D584A-F9E0-44E6-AF1D-9117E5F79697" ) myUuids_count: 2 Peripheral(UUID): 7D7D584A-F9E0-44E6-AF1D-9117E5F79697
プログラミング初心者のため初歩的な質問内容なのかもしれませんが、アドバイス頂けると幸いです。よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/16 05:25
2016/10/16 05:28
2016/10/16 07:40
2016/10/16 12:14