CoreBluetooth в Xcode IOS 13 не обнаруживает Bluetooth с других телефонов только на телевизионных устройствах - PullRequest
0 голосов
/ 18 апреля 2020

Добрый день, я пытаюсь обнаружить питание Bluetooth от соседних сотовых телефонов, но я распознаю только телевизоры, а не сотовые телефоны, никто не знает почему ... Я использую библиотеку CoreBluetooth в Xcode. спасибо за вашу помощь. Это мой код:

import UIKit
import CoreBluetooth

class ViewController: UIViewController {

    var centralManager: CBCentralManager!
    //var myPeripheral: CBPeripheral!
    var myPeripheral = Array<CBPeripheral>()
    var union: [String] = []
    var total: [String] = []

    @IBOutlet weak var tableView: UITableView!

        override func viewDidLoad() {
            super.viewDidLoad()
            //tableView.delegate = self
            tableView.dataSource = self

            // Do any additional setup after loading the view.
                    //centralManager = CBCentralManager(delegate: self, queue: nil)
            centralManager = CBCentralManager(delegate: self, queue: DispatchQueue.main)
            //let locationManger = CLLocationManager()
            //locationManger.requestWhenInUseAutotization()

        }
    }



extension ViewController: CBCentralManagerDelegate{
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        if central.state == CBManagerState.poweredOn {
            print("BLE powered on")
            // Turned on
            //let service = [CBUUID](string: "780A")

            self.centralManager?.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
        }
        else {
            print("Something wrong with BLE")
            // Not on, but can have different issuess

        }

    }
    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        print("Entro")
        myPeripheral.append(peripheral)
        //print(peripheral)
        tableView.reloadData()
        let rsi = RSSI.stringValue
        if let pname = peripheral.name {
            print(pname)
            print(rsi)
        }
        //    union = [pname + rsi]
        //   total = union + total
        //    print(total)
        }
    }
extension ViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:UITableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell
        let peripheral = myPeripheral[indexPath.row]
        cell.textLabel?.text = peripheral.name

        return cell
}

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return myPeripheral.count
}
}

Я использую tableView для отображения устройств на экране, а также добавляю два разрешения в файл info.plist с именами NSBluetoothAlwaysUsageDescription и NSBluetoothPeripheralUsageDescription. Что я мог сделать в этом случае?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...