I have to connect a remote server via tcp socket from the Watch.
I have already written a piece of code using CFStream which works perfectly from the Watch simulator.
When I run it on the Watch I get this error:
The operation couldn’t be completed. Can't assign requested address (Code = 49)
when I try to open the connection to the server using CFStreamCreatePairWithSocketToHost
.
The Apple documentation declares that CFStreamCreatePairWithSocketToHost
is
Available in watchOS 2.0 and later.
so I expected that it had should work but I have found this Apple's engineer answer which confirms that there is no way to open a tcp connection from the Watch:
Socket communication does not work real Apple Watch
Can anyone clarify and help me to understand?
Supposing that I cannot open a tcp connection from the Watch, what kind of alternatives have I, since I cannot use [NSURLSession]?
I could use one of the communication methods provided by [WCSession] but do they work when the iPhone app either is not running or is not in foreground?