2

In Objective-C, I subscribed to the UIWindowDidBecomeVisibleNotification to know if some view gets above my current view controller, using:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(videoStartedPlaying:)
                                             name:UIWindowDidBecomeVisibleNotification
                                           object:nil];

So far, so good. Then, in the notification, I could check if the object is not of certain classes (like _UIAlertControllerShimPresenterWindow -alert views- or UITextEffectsWindow -native sharing view-). In Objective-C, I did it this way:

- (void)videoStartedPlaying:(NSNotification *)notification
{
    if (
        <radio_is_playing>
        &&
        ! [notification.object isKindOfClass:NSClassFromString(@"_UIAlertControllerShimPresenterWindow")] // Alert view
        &&
        ! [notification.object isKindOfClass:NSClassFromString(@"UITextEffectsWindow") ] // Share
        )
    {
        // Video, stop the radio stream
    }
}

This allowed me to stop playing sounds (in this case, an HTTP radio streaming) when starting a video from a UIWebView (which is used to present news). I've tried to do the same thing in Swift, so I subscribed to the notification:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoStartedPlaying:", name: UIWindowDidBecomeVisibleNotification, object: nil)

And now, when receiving the notification...

func videoStartedPlaying(notification: NSNotification) {
    if <radio_is_playing> && !notification.object? is _UIAlertControllerShimPresenterWindow && !notification.object? is UITextEffectsWindow {
        // Stop the radio stream
    }
}

Xcode says Use of undeclared type '_UIAlertControllerShimPresenterWindow'. The same thing happens with UITextEffectsWindow.

I assume that I have to import something to detect those classes, but what should I import?

Is there any other way to do it without bridging Objective-C? How could I access that class?

Thank you in advance.

Alejandro Iván
  • 3,969
  • 1
  • 21
  • 30

1 Answers1

0

you could compare the class name instead the class itself, refer here to get the class name.

Community
  • 1
  • 1
Allen
  • 6,505
  • 16
  • 19
  • It's working with the first option. I saw that answer before and I don't know why it didn't work at that time. Thanks a lot. EDIT: For reference, if anyone else wants to do something similar, when presenting the share action (after pressing, for example, "Messages"), now a new event `UIRemoteKeyboardWindow` appears too. – Alejandro Iván Dec 28 '15 at 18:37