2

I'm using the pod of SDCAlertView, found here, to implement a series of alert messages with images and other features. The alerts are centered around audio events (ie. headset inserted or removed) and need to be dismissed sometimes without the alert button being clicked.

The issue occurs after I call dismissWithClickedButtonIndex: animated:. The call itself appears to work jut fine but once that alert is gone the next UIView becomes unresponsive.

One instance of the dismissWithClickedButtonIndex: animated: call happens in this callback:

- (void) audioRouteChangeListener: (NSNotification *)notification {
    // Initiallize dictionary with notification and grab route change reason
    NSDictionary *interuptionDict = notification.userInfo;
    NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];

    switch (routeChangeReason) {
        // Sensor inserted
        case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
            // Dismiss alert if any and begin collection
            if (self.sensorAlert != nil) {
                [self.sensorAlert dismissWithClickedButtonIndex:0 animated:YES];
                self.sensorAlert = nil;
            }

            // **** DEBUG ****
            NSLog(@"Sensor INSERTED");
            break;

        default:
            NSLog(@"Blowing it in- audioRouteChangeListener with route change reason: %ld", (long)routeChangeReason);
            break;
   }
}

I added the alertView handler didDismissWithButtonIndex: and confirmed the dismiss call is making it:

- (void) alertView:(SDCAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    switch (buttonIndex) {
        case 0:
            // Checking for dismiss
            NSLog(@"Made it to standard dismiss\n");
            break;

        default:
            NSLog(@"Uncaught dismiss\n");
            break;
    }
}

The SDCAlertView instance is part of a class that subclasses NSObject, as opposed to UIViewController, which I guess could be the cause of the issue but then I would assume the clickedButtonAtIndex call would cause the same effect but it does not.

I set up the SDCAlertView like so:

// Set up alert View for a disconnected sensor
self.sensorAlert = [[SDCAlertView alloc]
     initWithTitle:@"No Sensor"
     message:@"Please insert the GSF sensor and try again."
     delegate:self
     cancelButtonTitle:nil
     otherButtonTitles:@"Try Again", nil];

     [alertImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
     [self.sensorAlert.contentView addSubview:alertImageView];
     [alertImageView sdc_horizontallyCenterInSuperview];
     [self.sensorAlert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[alertImageView]|"
                                                                                             options:0
                                                                                             metrics:nil
                                                                                               views:NSDictionaryOfVariableBindings(alertImageView)]];

Any help in figuring out this problem is greatly appreciated.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
mickben
  • 385
  • 4
  • 11
  • I'm having trouble understanding what the exact sequence of presenting and dismissing is. You present one, dismiss it, present another one, and then the second one doesn't respond? – Scott Berrevoets Jun 04 '14 at 20:54
  • @ScottBerrevoets The sequence of events is: 1) Display an alertView 2) If an action occurs, inserting a headset, then dismiss the alertView programmatically. After the dismissing the alert the underlying view becomes unresponsive. – mickben Jun 04 '14 at 21:01
  • If I simulate that sequence, it works just fine for me. Any chance you can upload a dumbed-down sample project? – Scott Berrevoets Jun 04 '14 at 21:13
  • @ScottBerrevoets Yea. I have this stub app that I made a while back. I just updated it to demonstrate the issue [here](https://github.com/mick31/Headset-Sensors). – mickben Jun 04 '14 at 21:40
  • Even with that project I can't reproduce. Tapped "Collect", plugged in a headset, alert dismisses, but the next view with the Process button works fine for me... – Scott Berrevoets Jun 04 '14 at 22:03
  • @ScottBerrevoets Really You can navigate back to the main view after those steps? – mickben Jun 04 '14 at 22:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55098/discussion-between-studmuf-and-scott-berrevoets). – mickben Jun 04 '14 at 22:05

0 Answers0