Razvan N
Razvan N

Reputation: 654

Detect AirPlay Mirroring in iOS application

I have an iOS app built in XCode with Objective C mainly for iPads.

Basically I want to detect inside my application of AirPlay Mirroring is active, so mainly if the device is mirroring to another screen.

I searched all around stackoverflow but I couldn't find what I needed for this. Some answers said that I have to use UIScreenDidConnectNotification for this.

The thing is that I have to call a function if the mirroring is active or when mirroring is activated, also when mirroring is stopped. So I think I need a listener for the mirroring changes.

Can you please help me?

I am relatively new to iOS development so please don't get upset if I may not know all things.:)

Some answers I've found :

Thanks!

Upvotes: 2

Views: 3863

Answers (1)

Sergey Grishchev
Sergey Grishchev

Reputation: 12051

Here's how you can call any function by subscribing to the notification, you can do it in viewDidLoad or where you find necessary:

[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(receiveAirPlayNotification:) 
        name: UIScreenDidConnectNotification
        object:nil];

And to receive it:

- (void) receiveAirPlayNotification:(NSNotification *) notification
{
  //Do whatever you want here, or call another function
  NSLog(@"Received Notification - %@", notification); 
  [self doMyThing];
}

Upvotes: 2

Related Questions