postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
882 stars 96 forks source link

Replicate connection in iOS native App #2399

Open lidaamber opened 4 months ago

lidaamber commented 4 months ago

What do you need help with?

Hi! I checked that pyatv works with my apple tv, it establishes the connection correctly and sends commands as expected. I want to replicate the connection in native iOS app using Swift, but I fail to connect, doing seemingly the same things.

Could you please let me know if there is anything special about the connection via pyatv that might not work if doing the same from iOS app? Are there any special headers used in the connection or a non-standard handshake that could not work from iOS app? Thanks

postlund commented 4 months ago

There's nothing special that you couldn't do in Swift, no. You need to follow the protocol. As I have no idea what you have done nor what protocol or even function you are trying to implement, it's hard to give any pointers.

lidaamber commented 4 months ago

Sure, I totally understand Does pyatv send any specific headers when establishing the connection? Specifically in sendIntroduction()? Is there any way for me to debug what exactly is being sent when connection is established?

Thanks a lot in advance

postlund commented 4 months ago

There's no sendIntroduction() method in pyatv. You need to understand that pyatv implements five different protocols used by Apple products for various purposes. I can't tell you "generically" what "headers" are sent because it all depends on what protocol you are referring to. They are all very different. You can use --debug when running for instance atvremote, which will show a lot of debug output. But that will only get you so far.

What protocol are you implementing?

lidaamber commented 4 months ago

Sorry, I confused it with another solution I would like to use and establish connection through Companion Protocol, my goal is to establish connection to Apple TV and further use cursor control functions, listing apps and opening the app through deep link

At the moment I'm just trying to establish the connection to Apple TV, having the IP address of Apple TV and the port 49153

lidaamber commented 4 months ago

In debug mode with pyatv I can see that the connection is successfully established as Connected to companion device ip:port , but indeed, I can't see any details on the handshake and connection establishment itself. Details on that would be really helpful for me

postlund commented 4 months ago

Then I would refer you to this page:

https://pyatv.dev/documentation/protocols/#companion-link

It should explain most things you need.