2

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!

Razvan N
  • 554
  • 3
  • 9
  • 29

1 Answers1

2

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];
}
Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120
  • Sergey, thank you for your answer. I have a little question. The notification code should be added into the AppDelegate file? Thanks a lot! – Razvan N Jun 20 '17 at 10:18
  • 1
    @RazvanN I would add it to the view controller you need to use it in - so that you don't fill your AppDelegate with unnecessary dependencies. – Sergey Grischyov Jun 20 '17 at 13:34
  • Sergey, sorry to disturb you again. Can I ask you a question regarding some iOS private frameworks? I am trying to implement them to use AirPlay mirroring into an app and I cannot seem to be able to import them successfully into Xcode. Have you used the iOS runtime headers from this link : https://github.com/nst/iOS-Runtime-Headers ? – Razvan N Jun 28 '17 at 09:09
  • 1
    @RazvanN Hi! To implement AirPlay you don't need any private iOS frameworks - otherwise, your app will be rejected. And even if you choose to use private frameworks at some point, it's very hard to import them into your project, as Apple done everything it can to prevent you from using them. What you should use however are public dynamic frameworks that come with iOS - this way you're good to go. – Sergey Grischyov Jun 28 '17 at 09:33