Author Topic: RFDuinoManager.h - centralManager: didDisconnectPeripheral: error:  (Read 2277 times)

artandmath

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile

I was finding that if I lost connection with the RFduino (purposely turning it off) then the method "didDisconnectRFduino" was not getting called.
I'm not sure if I've modified the code correctly, but here it is. If the method didDisconnectRFduino is available in the delegate it will get called.



Code: [Select]
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
    NSLog(@"didDisconnectPeripheral");

    // original code, isn't calling the code block and is throwing the alert box
    /*
    void (^block)(void) = ^{
        if ([delegate respondsToSelector:@selector(didDisconnectRFduino:)]) {
            RFduino *rfduino = [self rfduinoForPeripheral:peripheral];
            if (rfduino) {
                [delegate didDisconnectRFduino:rfduino];
            }
        }
    };
   
    if (error.code) {
        cancelBlock = block;

#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
       
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Peripheral Disconnected with Error"
                                                        message:error.description
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
       
#endif
       
    }
    else
        block();
    */
   
    if ([delegate respondsToSelector:@selector(didDisconnectRFduino:)]) {
            RFduino *rfduino = [self rfduinoForPeripheral:peripheral];
            if (rfduino) {
                [delegate didDisconnectRFduino:rfduino];
        }
    }
    else{
   
        if (error.code) {
           
           
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Peripheral Disconnected with Error"
                                                            message:error.description
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
           
           
        }
    }
   
    if (peripheral) {
        [peripheral setDelegate:nil];
        peripheral = nil;
    }
}

bsiever

  • RFduino Full Member
  • ***
  • Posts: 89
  • Karma: +4/-0
    • View Profile
Re: RFDuinoManager.h - centralManager: didDisconnectPeripheral: error:
« Reply #1 on: July 28, 2014, 07:37:48 PM »
You might want to verify that the delegate is set correctly and still present (hasn't been deleted).

Perhaps you should run the app in XCode's debugger and put a breakpoint on the first line of "didDisconnectPeripheral". You can then use the debugger to see if the delegate is correct.

  Bill