更新到 OSX 12 并重新訪問舊專案后,我發現我的 CBCentralManager 介面代碼不再有效:
// this does get called
- (void) controlSetup
{
NSLog(@"BLE::controlSetup");
self.CM = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
- (int) findBLEPeripherals:(int) timeout
{
if (self.CM.state != CBManagerStatePoweredOn)
{
return -1;
}
[NSTimer scheduledTimerWithTimeInterval:(float)timeout target:self selector:@selector(scanTimer:) userInfo:nil repeats:NO];
//[self.CM scanForPeripheralsWithServices:nil options:nil]; // doesn't work
// also doesn't work
NSDictionary *scanOptions = @{CBCentralManagerScanOptionAllowDuplicatesKey:@(YES)};
[self.CM scanForPeripheralsWithServices:nil options:scanOptions];
return 0; // Started scanning OK
}
// rest of CBCentralManagerDelegate methods omitted for brevity
// is no longer triggered:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"BLE::didDiscoverPeripheral didDiscoverPeripheral");
}
CBCentralManager 屬性設定為強大且非原子的,因此我認為它不會在任何地方收集:
@property (strong, nonatomic) CBCentralManager *CM;
這個專案通常是 Unity 的一個插件,直到 OSX12.0 在編輯器和 Unity 構建的應用程式中運行時按預期作業。有沒有人想過為什么這可能突然停止作業或我可以嘗試什么?
uj5u.com熱心網友回復:
這可能是12.3 中修復的錯誤。
但是,如果可能,您應該掃描您的特定服務串列,而不是nil. 掃描nil通常僅適用于通用 BLE 掃描儀。我預計 macOS 上的 CoreBluetoth 將繼續向 iOS 方法發展,在這種方法中掃描nil服務非常有限,所以如果你不需要它,現在是洗掉它的好時機。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/426060.html
上一篇:在Apple地圖位置中顯示圖釘
下一篇:由于未捕獲的例外“NSInternalInconsistencyException”而終止應用程式,原因:“無效引數不滿足:pos”
