我實際上是使用Corebluetooth在iPhone和iPad之間交換信息.
我得iPhone充當中央,我得iPad充當外圍設備.
我正在宣傳我得服務但在我得中心時,我正在通過:
peripheral:didDiscoverServices:
我在該方法中獲得得peripheral.services是空得.
我錯誤地從外設斷開后幾秒鐘:
DISCONNECT-ERROR desc : Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo=0x16e60f90 {NSLocalizedDescription=The specified device has disconnected from us.}
我不知道發生了什么事.
編輯:
在中央方面我有這個:
-(void)startScanning{ [super startScanning]; // Scan for devices [self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:PERIPHERAL_SERVICE_UUID]] options:nil];}#pragma mark Peripheral Delegate- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error { if (error) { [self cleanup]; return; } for (CBService *service in peripheral.services) { [peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:NEW_COMMANDS_NOTIFIER_CHARACTERISTICS_UUID]] forService:service]; } // Discover other characteristics}- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { if (error) { [self cleanup]; return; } for (CBCharacteristic *characteristic in service.characteristics) { if (self.commandsFromIpadCharacteristic != characteristic) { self.commandsFromIpadCharacteristic = characteristic; } if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:NEW_COMMANDS_NOTIFIER_CHARACTERISTICS_UUID]]) { [peripheral setNotifyValue:YES forCharacteristic:characteristic]; } }}
在外圍方面,我有:
#pragma mark CBPeripheralManagerDelegate- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{ if (peripheral.state != CBPeripheralManagerStatePoweredOn) { return; } if (peripheral.state == CBPeripheralManagerStatePoweredOn) { self.datasFromIphoneCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:NEW_DATAS_FROM_IPHONE_CHARACTERISTICS_UUID] properties:CBCharacteristicPropertyWrite value:nil permissions:CBAttributePermissionsWriteable]; self.commandNotifierCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:NEW_COMMANDS_NOTIFIER_CHARACTERISTICS_UUID] properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable]; CBMutableService *transferService = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:PERIPHERAL_SERVICE_UUID] primary:YES]; transferService.characteristics = @[self.datasFromIphoneCharacteristic,self.commandNotifierCharacteristic]; [self.peripheralManager addService:transferService]; [self.peripheralManager startAdvertising:@{CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:PERIPHERAL_SERVICE_UUID]]}]; }}- (void)peripheralManagerDidStartAdvertising:(CBPeripheralManager *)peripheral error:(NSError *)error { if (error) { NSLog(@"Error advertising: %@",[error localizedDescription]); }}- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic { if (characteristic == self.commandNotifierCharacteristic){ // on envoie le message au delegate if([[self delegate] respondsToSelector:@selector(iPhoneIsConnectedToIpad:)]) { [[self delegate] iPhoneIsConnectedToIpad:YES]; } }}-(void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didUnsubscribeFromCharacteristic:(CBCharacteristic *)characteristic{ if (characteristic == self.commandNotifierCharacteristic){ // on envoie le message au delegate if([[self delegate] respondsToSelector:@selector(iPhoneIsConnectedToIpad:)]) { [[self delegate] iPhoneIsConnectedToIpad:NO]; } }}
編輯答案:
我發現了問題,在centralManager中:didConnectPeripheral:我沒有使用[peripheral discoverServices:]調用正確得服務UUID.謝謝您得幫助 :).
解決方法
我發現了問題,在centralManager中:didConnectPeripheral:我沒有使用[peripheral discoverServices:]調用正確得服務UUID.謝謝您得幫助 :).
以上是來客網為你收集整理得ios – Corebluetooth在連接后斷開連接全部內容,希望內容能夠幫你解決ios – Corebluetooth在連接后斷開連接所遇到得程序開發問題。
如果覺得來客網網站內容還不錯,歡迎將來客網網站推薦給程序員好友。
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。