WatchOS establish server connection

245 Views Asked by At

I have a client - server IOS application. In addition, I need to write an application for it on WatchOS. So I have 2 questions:

  1. When I send a command from Apple Watch, do I need to connect to the server from the watch or transfer information to the IOS application and connect to the server from the phone?

  2. If I have to connect to the server with an IOS application, then how can I connect in background mode?

As an example, you can take any messenger, for example Telegram If I reply to a message with AppleWatch, how is the message being sent to the server (Via iPhone or directly via AppleWatch) For connection to the server, I use the "Starscream" framework

Maybe I don't understand something, but Apple made it impossible to establish a connection in background mode

I would be grateful if you tell me or provide examples and articles, so that I could understand what to do.

1

There are 1 best solutions below

2
On BEST ANSWER

Apple Watch apps can connect directly to servers using URLSession ... no need to go via the phone.

Here is an example on using URLSession in Combine, which is the "latest and greatest" way of doing things.

Otherwise this example shows using it in a more conventional way, with the bonus of SwiftUI.

Otherwise