One of the hardest things about being a Mac developer is wading through tons of search results for APIs that only exist on iOS.

Looking at you, AVAudioSession.

If anyone knows how to detect if AirPlay is active on a Mac, I'd love to know! I already know how to do it on iOS 😉

Thankfully, there are fewer and fewer cases where this is an issue. Apple continues to get better at cross platform support.

One of the benefits of SwiftUI and Mac Catalyst, even if you don't use them.

@chockenberry the only option is a handwritten request to Tim Apple himself
@chockenberry and even that doesn’t work in Ventura
@chockenberry Don't leave me hanging. How do you do it on iOS?
@nighthawk AVAudioSession.shared.currentRoute.outputs has one or more portType for AirPlay.
@chockenberry Have you hit up @marcoarment ? Marco's been smashing his head against the AirPlay system for yonks. Hopefully he's got the info to go with his concussion.

@jeffcgd @chockenberry Sorry, I only know it from the iOS side.

When Overcast runs on the Mac (in “made for iPad” mode), the stock AirPlay-picker control doesn’t even render. Seems like it’s basically unsupported.

@marcoarment @jeffcgd @chockenberry

This would be an interesting ChatGPT question 


@jgordon @marcoarment @chockenberry

Probably not, presuming you actually wanted to get the RIGHT answer, as opposed to just a confident sounding wrong one.

@jeffcgd @marcoarment @chockenberry

I’ve read that ChatGPT is actually pretty good at this type of question. I’ll try if I remember. Bookmarking for now.

@jeffcgd @marcoarment @chockenberry

(On reflection Google is awful when the answer is “no” or “that can’t be done as far as I know”. I gather ChatGPT is even worse at “knowing what it doesn’t know”.)

@jgordon @jeffcgd @marcoarment @chockenberry
I’m my experience it pretends to know based on your question. I’ve had plenty of Swift answers that look right but don’t work. ChatGPT has no knowledge of the API. It’s just a language model.

@robmac @jeffcgd @marcoarment @chockenberry

I've not done much with ChatGPT so my prompt was off. Not a terribly useful answer for Craig I think.

@jgordon @jeffcgd @marcoarment @chockenberry
Here is ChatGPT making up shit as usual. Searching the API finds nothing for “.withAirPlay”.
@jgordon @jeffcgd @marcoarment @chockenberry
And then it makes up something else that doesn’t work.

@jgordon @jeffcgd @marcoarment @chockenberry
Then it came up with this, after I complained that the function on returned whether AirPlay was available, not active. I have no idea if this works or not. My hunch is that it won’t work.

func isAirPlayActive() -> Bool {
guard let mainScreen = NSScreen.main else {
return false
}
let options = mainScreen.deviceDescription[NSDeviceDescriptionKey("AirPlayDisplay") as NSDeviceDescriptionKey] as? [String: Any]
return options?["DeviceInUse"] as? Bool == true
}