Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Inter Process Communication possible between iOS applications using Sockets?

Tags:

ios

sockets

ipc

I have gone through a lot of articles on internet and most say that IOS applications allow IPC using protocol handlers (URL Schemes). But, Can't we achieve IPC using sockets, if one application opens a port and the other tries to connect to it ?

like image 990
Cyberzomie Avatar asked Oct 15 '14 02:10

Cyberzomie


People also ask

Is socket an inter process communication?

Sockets provide point-to-point, two-way communication between two processes. Sockets are a basic component of interprocess and intersystem communication. A socket is an endpoint of communication to which a name can be bound.

What is the IPC mechanism for iOS?

Inter Process Communication (IPC) is a method that allows processes to send each other messages and data. It is a form of communication available on multiple multitasking platforms and implemented on various languages. This page focuses on C family based IPC for iOS programs.

What are the two main methods for inter process communication?

A process can be of two types: Independent process. Co-operating process.

Which method is used for inter process communication?

Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO. It is important to obtain synchronization among processes in IPC to maintain data consistency. Semaphore and mutex are two ways to do so.


2 Answers

iOS8 introduced IPC support by exposing mach ports for so called "application groups". Check out this great tutorial:

http://ddeville.me/2015/02/interprocess-communication-on-ios-with-mach-messages/

It requires a bit of setup (to define application groups in dev portal, generate proper entitlements, etc..) but is not really so difficult and Xcode 6 does most of the job automatically (just enable "App groups" in general capacities section).

I can confirm, it works (I was able to create 2 apps sending messages to each other).

On iO7 there is no official support for IPS, but If you do not plan to upload your app to AppStore, you could try to exploit inter-app audio communication to achieve this. Check out Apple's code sample, which demonstrated inter-app sound data stream between 3 apps:

https://developer.apple.com/library/ios/samplecode/InterAppAudioSuite/Introduction/Intro.html

Associated WWDS video:

https://developer.apple.com/wwdc/videos/#602

I haven't try to exploit it for non-audio usage but can't see the reason why shouldn't it work. Data rate is great, and sound data are just bytes and do not have to be redirected to the speaker, but interpreted however you like.

Of course, it will be rejected in AppStore review, but it is still fine for enterprise or own usage.

like image 159
Lukasz Avatar answered Oct 16 '22 14:10

Lukasz


No, it is not for several reasons. 1) Apple does not allow this internally and has security layers to prevent this. 2) Applications fire applicationDiD/WillEnterBackground after a short delay, at which point the way you can interact with it plummets.

If you really want to send data between applications, set up a server with certs to match your app so you can use APN (apple push notifications) to send data in silent pushes to applications. Then, set up endpoints on the server that trigger those sends, and have apps consume the API that the server exposes.

like image 2
Michael Voznesensky Avatar answered Oct 16 '22 15:10

Michael Voznesensky