0

I want to build a simple app in iOS using swift which shows the photos of the album in my app and on button click it should airplay on my Apple TV.

I read so many documents and articles but not sure if we can do it for photos. Few have said for audio/video it is possible but not sure about photos.

At least any links or sample code would be helpful.

Thanks

Bhavik Modi
  • 1,517
  • 14
  • 29
Manisha
  • 372
  • 3
  • 13
  • look at this link https://stackoverflow.com/questions/8231868/ipad-airplay-and-mirroring-sdk-support not sure whether will work or not – Gagan_iOS May 10 '19 at 10:44
  • 1
    There is no API to do it without user interaction . You may be able to use AVRoutePickerView to let the user select a destination from within your app if you are using the AV framework to show the photos. – Paulw11 May 10 '19 at 11:08
  • @Paulw11, please help! Can I mirror the app screen rather than showing photos/videos in swift programmatically? Any idea to mirroring ios app on airplay supported/smart tv programmatically? – Jamshed Alam May 25 '21 at 02:14
  • @Paulw11, please put a comment here if possible, I did not get the exact starting clue still. https://issuetracker.google.com/issues/188566061?pli=1 – Jamshed Alam May 25 '21 at 02:16
  • I do not believe that there is any api to mirror the device screen programmatically. The user needs to do it via control center. A lightning to hdmi adapter mirrors the screen automatically. – Paulw11 May 28 '21 at 09:59

1 Answers1

4

A user should connect the to Apple TV at Control Center via AirPlay:

Control center AirPlay

Then you can use Apple TV as second screen of the app.

  1. Check if the app have external display:

    if UIScreen.screens.count > 1 {
        // External display is connected ...
    }
    
  2. Create new UIScreen for external window:

    if let externalScreen = UIScreen.screens.last {
        externalWindow = UIWindow()
        externalWindow.screen = externalScreen
        configureExternalWindow(externalWindow)
        externalWindow.isHidden = false
    }
    
  3. And use it as you want to display photo albums:

    // In our Collection View selection callback
    if inSingleDisplayMode {
        photoViewController.photo = photo
        navigationController?.pushViewController(photoViewController, animated: true)
    } else {
        showOnExternalDisplay(photo)
    }
    

Additional information at WWDC sessions:

Adding Delight to your iOS App

AirPlay and External Displays in iOS apps

Anton Vlasov
  • 1,372
  • 1
  • 10
  • 18
  • thanks for example, let me try and I will update on same. – Manisha May 13 '19 at 04:52
  • @Anton, Can I mirroring the app screen rather showing photo/video in swift programmatically in swift? Any idea to mirroring ios app on airplay supported/smart tv ? – Jamshed Alam May 25 '21 at 02:12