问题描述
我相信蓝牙回调阻止了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 (将#修改为@)