iOS using sockets to talk to other apps - ios

Is it possible to have 2 apps on 1 iPhone/iPad talk to another via sockets? For example The main app is phonegap app that just displays data and when the user clicks the print button, the 1st app sends data to the 2nd (2nd app stays in the background, I guess it is a service), it (the 2nd app) then sends that data to a printer that it knows how to talk to whether that is via a webservice call or something else.
From my scan of the docs and other questions it seems the custom URL is one way to make the apps talk, but I want the receiver app to stay in the background. So do I have to use a server/client approach to this? Is that possible.

Sure you can. Just make sure your 2nd app - the background app is conformed to Apple's requirement to run in background modes. You can also use Bonjour to aid in discovery or just pre-selected a port and make other apps aware of it value.

No, there is no socket-based interprocess communication between apps on an iPhone, nor is there any concept of apps as background services. Using custom URLs to launch another app is the only direct method of communication between apps.
On the other hand, if the 2nd app is talking to a printer (or anything else) via a web service, I'm not sure why you wouldn't just have the 1st app use that web service to print directly. Is there a particular reason you need a background app to perform this function?

Related

iOS App that controls the screen also when backgrounded

Is there any way to implement an iOS app that has access to the screen (e.g. screen recording) also when it's backgrounded? Has anyone experience with this?
Apps like TeamViewer do this, but it's not clear to me if they went through a special process with Apple (e.g. a non-open API).
P.S. I am of course assuming that the user would have to explicitly accept this (e.g. like for system extensions on macOS), the goal here is not to make a malicious app but a remote-control tool.
The only way to record the screen in the background is by using the broadcast upload extension in ReplayKit 2. This WWDC talk goes into more detail around how to use this API https://developer.apple.com/videos/play/wwdc2018/601/
Since it's not specifically designed for your use case you will have to do some things differently like locally storing the frames in your App Group instead of uploading them.

Does Apple permit the usage of socket for communication between two iOS apps?

So basically I have two iOS apps installed on the same device, and they need to communicate by sending data to each other. I don't want to use URL scheme or Universal links as these two would open the other app in UI instead of sending message to each other in the background. Currently I have a solution of using a unix socket connection by binding one app to a specific port and have another app connect to it. This works fine but I am just wondering if Apple would allow the usage of this.
Note that these two iOS apps do not come from the same developer so anything else that relies on App Group would not work in this case..
Would Apple allow using a socket in this case?
Edit: One of the app is valid to run in background, so background execution is not a problem
No, this is not possible simply because the application will lose network connectivity when it goes into background mode. I invite you to check the following Apple Developer Documentation page related to iOS app background modes:
Background Execution
As you can find on the page, the operating system suspend the app when it moves to background and will then cut several resources including network access.
There are however some exceptions to the rule, which are voice ip apps. These must declare the voip background mode in the plist file to be allowed to keep network streams open in the background.
This question comes a lot on iOS or Android and unfortunately the answer so far is no, we can do tcp client / server communication between apps.
It is totally doable as long as one of your apps has permissions to run on the background. Such example is music apps. Spotify does the same thing with their “app-remote” SDK.

Calling number with iPhone on External Signal

What I am trying to accomplish is to make ios app that listens to signal (not yet defined in which form) and then call the number specified in received message. I've found that is impossible when app is in background due to Apple privacy policy, but I want it to be possible only when in foreground.
I am wondering if it is possible to develop similar mechanism like when you connect iPhone to MAC so you can call using your MAC. But I want to use this funcionality from Windows too.
For example. Lets say that I have Windows app written in Java that stores contacts. I click call and the number is send to iPhone (like I said using not specified yet method) and then iPhone calls that number.
Is there any possibility to accomplish this. If yes, what the best way to send and receive message with number (for example bluetooth ).

iPhone app with call features

I'm trying to get into a new project, by creating an iOS application. But before I start I would like to understand some points:
is it possible to let an application make a phone call? So what I mean is, assumed we have a phone number and would like to call it. Would it be possible to use an (my) application to call this number?
is it possible to let an application speak during a phone call? So after the application started the call, would it be possible that some predefined statements are said in the call?
is it possible that this application hears, registers and analyses what the other person on the phone line is saying? (Leaving apart the privacy issue, assuming that the other person is willing to do that).
Could you please help me? If my question aren't clear, please tell me, I will try to explain it in another way.
Many Thanks
F.P.
iOS is very restricted in terms of the system behaviors third party applications can influence.
To answer your question bluntly, a third party application could prompt the user to initiate a phone / FaceTime call. Once the call is initiated however, your app would enter a background state and relinquish control to the system. The app would not be able to contribute or read any data related to the system phone / FaceTime call.
iOS 10 introduces a VoIP extension, CallKit, which allows third party apps to use the built in calling UI with a custom protocol. You could implement your own protocol (and host servers for handling the exchange of information) and build an extension to make it feel like a system call. You'd be responsible for all aspects of the custom call protocol and thus reading voices, contributing audio, etc. would all be possible (and up to your implementation).
Outside of iOS 10, you would have to built your own VoIP system and interface entirely from scratch.
For more info on CallKit:
WWDC Enhancing VoIP Apps with CallKit
CallKit Enabled Sample App

Sharing information between apps

There are two applications. How can they share information? Can we use a common database for them? Perhaps we can pass parameters from one application to another?
You cannot directly share any resources; every app is in its own "sandbox" and cannot access the resources of any any other app.
You can send data back and forth between apps a couple of ways, however.
If you want everything to stay on the device then you can implement application:openURL:sourceApplication:annotation: in both apps and provide a custom URL handler for both. The user will experience the device switching between the apps as they launch each other.
If you are willing to use a server and internet connection, then both apps can read and write the same server resource. When each app launches or becomes active, it can check for updated information on the server.

Resources