我開發了一個藍牙應用程序,它在iOS 6上運行良好,但是當我在iOS 7上運行它時,應用程序在-didDiscoverPeripheral回調中崩潰。崩潰信息表明在CBPeripheral對象上調用了一個發行版。我已經使用ARC內存管理,這裏是我的聲明中,CBPeripheral對象和回調代碼初始化:iOS 7中的核心藍牙故障
@interface BrLEDiscovery() <CBCentralManagerDelegate, CBPeripheralDelegate> {
CBCentralManager *centralManager;
CBPeripheral *currentperipheral;
BOOL pendingInit;
}
- (id) init
{
self = [super init];
if (self) {
pendingInit = YES;
centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
currentperipheral=[[CBPeripheral alloc]init];
founddevice=FALSE;
foundPeripherals = [[NSMutableArray alloc] init];
connectedServices = [[NSMutableArray alloc] init];
}
return self;
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{ NSLog(@"Found Peripheral %@",[peripheral name]);
if ([[peripheral name] isEqualToString:peripheralname]) {
founddevice=TRUE;
currentperipheral=peripheral;
if (![foundPeripherals containsObject:peripheral]) {
[foundPeripherals addObject:peripheral];
[discoveryDelegate discoveryDidRefresh];
[discoveryDelegate DiscoveryDidFindDevice:peripheral];
}
[RecursiveScanTimer invalidate];
}
}
什麼是錯誤?請張貼它。考慮到流程控制和語法,代碼本身看起來或多或少都不錯。 – allprog