Communicate between iOS and macOS ?

I should make an app for macOS and iOS that will communicate between them by sending Strings to each other, is it possible and how? Thanks

Thanks! Can I ask one more thing, is with this frameworks possible to make app for macOS that will communicate with Android (in both directions)? If Android can implement Bonjour to your app, and as I read they can.

is it possible and how?

As @MobileTen has mentioned, if your iOS and macOS devices are on the same local network then Bonjour would be a great option to setup this communication. The Building a Custom Peer-to-Peer Protocol sample project demonstrates how to use Bonjour between two iOS devices, but the same can be applied for macOS and iOS.

The idea is that one device would advertise a Bonjour service while other devices on the network browse for this service. When one device finds the service, it is handed an NWEndpoint and makes a connection with the NWListener advertising the Bonjour service. Once connected to the listener, both devices can start communicating.

Regarding:

is with this frameworks possible to make app for macOS that will communicate with Android

I'm not an Android expert but I do know that Bonjour, or multicast DNS (mDNS), is supported on a wide range of platforms to make this communication style ubiquitous. A quick browser search for Bonjour support on Android should turn up something.

Also note that here is Apple's homepage for Bonjour along with the source published for mDNSResponder here for more information.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

We implement Bonjour in Android and macOS see Android device via Bonjour. But how now connect these two device and that they communicate?

You're effectively asking how to implement networking in a heterogeneous peer-to-peer environment. That phrase and some keywords from the above answers should give you search strings. I used a variation of that and got to a Stack Overflow topic entitled Android/iOS Peer-To-Peer architecture [closed] (can't link to SO from here) and to the above-linked Apple Support article on peer-to-peer protocols.

You might also find yourself incorporating and using libtls or libsodium (can't link to that) for network communications here, as most of these cases will want encrypted connections.

Stanford CS193A provides an intro to Android including networking, and CS193P is the equivalent course for iPhone and iPad development. Both have classes posted on YouTube.

For an app that is cross-platform, networked, and targets secure communications, Signal has source code posted.

Depending on exactly what you're doing, Unity or another third-party product might be of interest here, too.

We're doing an app where Android and Mac send messages between each other. So far we managed to handle Android <-> Android, iOS <-> iOS and MacOS <-> iOS. We used Bonjour (NSD in Android) for discovery. When it comes to Android <-> iOS/Mac, they discover each other fine but the connecting is problematic.

On Android's end, to start we used Google's old nsdChat, converted to Kotlin and added coroutines to free up the main thread. On the Mac, we used Apple's Peer-to-Peer sample project of TicTacToe. Like I said, both apps work fine on their own OS.

Doing Android<->iOS/MacOS, after we register Android's service, Bonjour on Mac recognizes it. Android discovers the Mac too and resolves the service. After connecting, Android says it connected a client socket and manages to send a message before getting a random symbol back from Mac's side although no one sends it, before closing the connection. On the other side, when you click on Android's "Connect", Mac doesnt immediately shows any signs that they connected, but when you send the message from Android it shows some errors. (so there was something between them)

We're inexperienced in the Networking part, but we suspect it has something to do with the protocols, as it mentions SSL and TLS. Not sure if we have to do some extra modifications to it to work. Is it as simple as adding a SSL socket to Android and that that would fix the connection? There are practically no examples online, and literature is pretty scarce (all are mostly decidated to their own OS's, without cross functionality). I can expand more (add our code, explain further etc.) if there is someone who knows what's wrong/missing.

I recommend that you temporarily disable TLS, just to get started. Once you’ve got basic connectivity working, you can re-evaluate your TLS options.

For context, TLS was designed to work on the wider Internet, where the server has a stable DNS name (if you’re curious about this standard setup, see TLS for App Developers). It is possible to use TLS in a peer-to-peer environment but it’s kinda tricky. One option with the Network framework is to TLS pre-shared key (PSK). However, that’s a dark and dusty corner of the TLS spec and thus I’m not sure how well it’s supported on other platforms. Hence my advice to get this working without TLS first, and then you can research your TLS options.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes, without TLS we have a connection but some strange messages appear when we send from Android -> iOS, and also iOS -> Android. We try with TLC options with a pre-shared key but then fail to connect.

without TLS we have a connection

Cool.

We try with [TLS] options with a pre-shared key but then fail to connect.

OK. Given that TLS PSK works between Apple platforms, I think that’s a question you should escalate via the support channel for Android.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Communicate between iOS and macOS ?
 
 
Q