蓝牙回调阻止collectionView cellforitem函数被调用

问题描述

我相信蓝牙回调阻止了collectionView cellForItem函数的调用,尽管我没有证据。

以下是相关的蓝牙代码:

   func centralManager(_ central: CBCentralManager,didDiscover peripheral: CBPeripheral,advertisementData: [String: Any],rssi RSSI: NSNumber) {
    

    guard RSSI.intValue >= -150
        else {
            os_log("Discovered perhiperal not in expected range,at %d",RSSI.intValue)
            return
    }
    
    var detectedServiceCBUuids = advertisementData[CBAdvertisementDataServiceUUIDsKey] as? [CBUUID] ?? []
    if let detectedOverflowCBUuids = advertisementData[CBAdvertisementDataOverflowServiceUUIDsKey] as? [CBUUID] {
        detectedServiceCBUuids.append(contentsOf: detectedOverflowCBUuids)
    }
    for detectedServiceCBUuid in detectedServiceCBUuids {
        print("I detected serviceUuid: \(detectedServiceCBUuid.uuidString)")
        for discoverableCBUUID in discoverableCBUUIDS {
            if discoverableCBUUID == detectedServiceCBUuid {
                print("We have a CBUUID match between detected and discoverable")
                if self.detectedCBUUIDs.contains(detectedServiceCBUuid){
                    return
                }
                self.detectedCBUUIDs.append(detectedServiceCBUuid)
                print("self.detectedCBUUIDs count is ",self.detectedCBUUIDs.count)
                print("the array is now like this: ",self.detectedCBUUIDs)
                centralManager.stopScan()
                DispatchQueue.main.async {
                    self.collectionView.reloadData()
                }
                
            }
        }
        
       
    }

    if discoveredPeripheral != peripheral {

        discoveredPeripheral = peripheral

        os_log("Connecting to perhiperal %@",peripheral)
        centralManager.connect(peripheral,options: nil)
        
    }
}

以下是相关的收藏查看代码:

override func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
   
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId",for: indexPath) as! VideoCell

    if users.count != 0 {

        print("users count is not 0,so checking if detectedCBUUIDs is 0...")

        if self.detectedCBUUIDs.count != 0 {

            print("detectedCBUUIDs is not 0,so finding the matched user...")

            for user in users {

                print("trying user named ",user.name)

                if let userUUID = user.userUUID() {
                    let userCBUUID = CBUUID(string: userUUID)
                    print("potential match CBUUID is ",userCBUUID)
                    print("detected CBUUID is ",self.detectedCBUUIDs[indexPath.item])

                    if userCBUUID == self.detectedCBUUIDs[indexPath.item]{
                        if let name = user.userName(),let uuid = user.userUUID(),let profileImageUrl = user.userProfileImageUrl() {
                            print("user name is ",user.name)
                            cell.titleLabel.text = user.name
                            cell.userProfileImageView.loadImageUsingCacheWithUrlString( profileImageUrl)
                            DispatchQueue.main.async {
                                self.collectionView.reloadData()
                            }
                            return cell
                        }
                    }
                }

            }

        }

    }

    cell.titleLabel.text = self.broadcastCBUUID.uuidString
    cell.titleLabel.text = "No Discoverable Friends"
    return cell
}

我正在尝试使用蓝牙发现CBUUID,然后用它来识别用户并在collectionView中显示该用户。

提前谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...