0

When adding RPSystemBroadcastPickerView to my custom view on iOS 12, and send touch event to its internal button, UI blocked and cannot response any touch event.

Here is my code: When I receive a notification, I call this method to init my custom view:

- (void)presentMyCustomView
{
    MyCustomView *myCustomView = [[[[UIApplication sharedApplication] delegate] window] viewWithTag:kMyCustomViewTag];
    if (!myCustomView)
    {
        myCustomView = [[MyCustomView alloc] init];
        myCustomView.tag = kMyCustomViewTag;
        [[[[UIApplication sharedApplication] delegate] window] addSubview:myCustomView];
        [myCustomView release];
    }
}

In MyCustomView class's init method, I create RPSystemBroadcoatPickerView and add it to MyCustomView:

RPSystemBroadcastPickerView *broadcastPicker = [[RPSystemBroadcastPickerView alloc] initWithFrame:CGRectMake(0, 0, 100.f, 100.f)];
broadcastPicker.preferredExtension = @"xxxxx";
self.broadcastPicker = broadcastPicker;
[self addSubview:broadcastPicker];
[broadcastPicker release];

But when I run my project, sometimes UI blocked and all other elements on MyCustomView cannot be touched. RPBroadcastPicker crash log will be found in device logs but not everytime general crash log.

I have used many methods, for example, add broadcastPicker to the key window directly, but cannot help.

Anyone can help me? Many thanks.

Michael Yuan
  • 73
  • 1
  • 8
  • where is the code that fails? – Milan Nosáľ Dec 07 '18 at 08:25
  • Nothing failed but UI freeze. RPSystemBroadcastPickerView appeared on my custom view but cannot be touched. Other buttons also cannot be touched. – Michael Yuan Dec 07 '18 at 08:39
  • From what you are saying, I doubt the problem is in `RPSystemBroadcastPickerView` - use a normal button instead, and see if it works.. If not, then you are looking for a bug in a wrong place – Milan Nosáľ Dec 07 '18 at 08:55
  • If I only add a normal button, it works fine every time. But if I add RPSystemBroadcastPickerView, sometimes any touch events cannot be received. – Michael Yuan Dec 10 '18 at 03:30
  • @MichaelYuan, did you got any solution for freeze? – iOS Lifee Apr 19 '19 at 06:26
  • @iOSLifee yes, here is my solution for UI freeze. 1, Use method swizzling to hook UIViewController's init, viewDidLoad and viewWillDisappear methods. 2, You can NSLog to see which controller been create and didLoad when use RPSystemBroadcastPickerView. – Michael Yuan Apr 23 '19 at 01:56
  • @iOSLifee when RPBroadcastPicker crashed, RPBroadcastPickerStandaloneViewController covered on my UI, that's why my UI "freezed". So I will dismiss RPBroadcastPickerStandaloneViewController when send touch event to RPSystemBroadcastPickerView. – Michael Yuan Apr 23 '19 at 02:11
  • @MichaelYuan, actually my app only freeze on iPhone X and in other devices it's working fine – iOS Lifee Apr 23 '19 at 06:35
  • @MichaelYuan can you share me that code??? – iOS Lifee Apr 23 '19 at 06:36
  • @iOSLifee This is my demo code:https://github.com/jilaiyuan/RPSystemPickerDemo.git – Michael Yuan Apr 24 '19 at 02:07

1 Answers1

1
if (@available(iOS 12.0, *)) {
    RPSystemBroadcastPickerView *pickerView = [RPSystemBroadcastPickerView new];
    pickerView.preferredExtension = @"com.apple.sharescreen";
    SEL buttonPressed = NSSelectorFromString(@"buttonPressed:");
    if ([pickerView respondsToSelector:buttonPressed]) {
        [pickerView performSelector:buttonPressed withObject:nil];
    }
}
Mike Glukhov
  • 1,758
  • 19
  • 18