总的来说一切正常 . 数据发送/接收效果很好 . 但有时我会遇到一些像这样的崩溃:

Fatal Exception: Invalid Object  
0  CoreFoundation                0x181cb3164 __exceptionPreprocess  
1  libobjc.A.dylib                0x180efc528 objc_exception_throw  
2  CoreFoundation                0x181cb30ac -[NSException initWithCoder:]  
3  CoreBluetooth                  0x18716fecc CBXpcCreateXPCObjectWithNSObject  
4  CoreBluetooth                  0x18716fcd4 __CBXpcCreateXPCDictionaryWithNSDictionary_block_invoke  
5  CoreFoundation                0x181b811c0 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]  
6  CoreBluetooth                  0x18716f220 CBXpcCreateXPCDictionaryWithNSDictionary  
7  CoreBluetooth                  0x18716f0cc -[CBXpcConnection _allocXpcMsg:args:]  
8  CoreBluetooth                  0x18716e640 -[CBXpcConnection sendMsg:args:]  
9  CoreBluetooth                  0x187177eb8 -[CBManager sendMsg:args:]  
10 CoreBluetooth                  0x1871743f0 -[CBPeripheralManager updateValue:forCharacteristic:onSubscribedCentrals:]  
11 GearManager                    0x10077448c -[SGPeripheral sendPacket:] (SGPeripheral.m:376)  
12 CoreBluetooth                  0x1871767f4 -[CBPeripheralManager handleReadyForUpdates:]  
13 CoreBluetooth                  0x187177784 -[CBPeripheralManager handleMsg:args:]  
14 CoreBluetooth                  0x18716f560 __30-[CBXpcConnection _handleMsg:]_block_invoke  
15 libdispatch.dylib              0x181632a54 _dispatch_call_block_and_release  
16 libdispatch.dylib              0x181632a14 _dispatch_client_callout  
17 libdispatch.dylib              0x18163c96c _dispatch_queue_serial_drain$VARIANT$mp  
18 libdispatch.dylib              0x18163d2fc _dispatch_queue_invoke$VARIANT$mp  
19 libdispatch.dylib              0x18163f570 _dispatch_main_queue_callback_4CF$VARIANT$mp  
20 CoreFoundation                0x181c5b344 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__  
21 CoreFoundation                0x181c58f20 __CFRunLoopRun  
22 CoreFoundation                0x181b78c58 CFRunLoopRunSpecific  
23 GraphicsServices              0x183a24f84 GSEventRunModal  
24 UIKit                          0x18b2d15c4 UIApplicationMain  
25 GearManager                    0x10076c5fc main (main.m:26)  
26 libdyld.dylib                  0x18169856c start

请在[CBPeripheralManager updateValue:forCharacteristic:onSubscribedCentrals:]中说明此崩溃的原因 .

这是我的代码片段:

ConnectedCentrals,CBService和Characteristics是该类的私有对象 .

Send Packet:

-(void)sendPacket:(NSData*)packet
{
    BOOL sendingResult = true;
    if (connectedCentral != nil) {
        sendingPacket = sendingPacket != nil ? nil : packet;
        sendingResult = [peripheralManager updateValue: packet forCharacteristic:readCharacteristic onSubscribedCentrals:@[connectedCentral]];
        if (sendingResult) {
            CLLog(@"%@ [Success], packet [%d]", sendingPacket != nil ? @"sending" : @"re-sending",++count);
            sendingPacket = nil;
            [self.delegate onPacketSent:YES];
        }
    } else {
        CLLog(@"sending failed, connected central nil");
        sendingPacket = nil;
        if (self.delegate != nil) {
            CLLog(@"auto connecting");
            [self.delegate onChangeBleStatus:SGBLEStatus_AutoConnecting];
        }
    }
}

When Peripheral is ready to send New Packet:

- (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral
{
    CLLog(@"ready to send");
    if( sendingPacket != nil) {
        [self sendPacket:sendingPacket];
    } else {
        CLLog(@"re-sending [Fail]");
        [self.delegate onPacketSent:NO];
    }
}