3

I want to know code to call the actionsheet AirPlay directly. I want to achieve in the code for "AirPlay button pressed". In other words, I would like to call the "action sheet AirPlay" from anywhere. Thanks.

Adolfoi_
  • 43
  • 1
  • 6

1 Answers1

4
- (void)showAirPlay
{
    MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:volumeView];

    for (UIButton *button in volumeView.subviews)
    {
        if ([button isKindOfClass:[UIButton class]])
        {
            [button sendActionsForControlEvents:UIControlEventTouchUpInside];
        }
    }
}

Add the MPVolumeView to your view, and then send control events to the button. Keep in mind that this is very unstable because if Apple adds another UIButton to MPVolumeView, this will break.

maxned
  • 393
  • 2
  • 16
  • I guess to work around the issue of multiple buttons, one could customize the AirPlay button image which is a public method on the `MPVolumeView` class and check for that when iterating the buttons? – Roberto Andrade Aug 06 '15 at 19:53