iOS - Possible for Safari HTML5 Web Sockets to Communicate with App on Same Device? - ios

Is it possible to use html5 web sockets in mobile safari to communicate with another app on the same device? Basically, I'd like to build a socket server in a custom app and have my javascript on a page in mobile safari send messages to it via html web sockets. I have very little experience with sockets and just thought I'd throw this idea out there.

No -- there is no background mode which will allow a native iOS application to "legally" keep a socket server running. The only three modes which can fully run in the background are "audio", "VoIP", and "location", and your application probably wouldn't fall into any of these categories.

Related

Web Bluetooth send text from phone to browser

I've been doing a lot of reading and research on Web Bluetooth.
I just want to send some text from a BLE Server (in this case a web app running on iOS WebBLE app)...and have the text appear on another web app running on Chrome on my Mac.
I just want a textarea and a send button for the Server and a dynamically updatable span on the client.
Seems like all tutorials assume Server is some kind of peripheral (monitor, light bulb, etc)..and that you just have to write Client code to interact with it.
Is it possible to do this? Seems like it should be simple. Thanks
I guess I'm asking how to turn desktop Chrome into peripheral device using Web BT
How can I get my Mac browser to advertise using Web BT?
The Web Bluetooth API does not include APIs for acting in the peripheral role. A page using the API can only take on the role of the central.

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.

Can i run WebSocket server in background application in iOS

When i tried to implement app stays unto 3 mins after socket is not running.
My requirement to develop one socket server app that should be always in background.Needs to communicate with other client apps or safari web browser client .
I need to communicate between server app and other clients apps or other browser.
So, initially user opens the server app and click start server button.Then he can go to other clients apps and get communicate and share valuable information.
In this process server app needs to stay in background continuously for a long time.Untill the user terminates the app.
I saw that app need to use some UIBackgroundModes to communicates like
• Apps that play audible content to the user while in the background, such as a music player app
• Apps that record audio content while in the background
• Apps that keep users informed of their location at all times, such as a navigation app
• Apps that support Voice over Internet Protocol (VoIP)
• Apps that need to download and process new content regularly
• Apps that receive regular updates from external accessories
But i am using only external accessories in my app.That i am attaching some reader to iPhone/ipad device.
• Apps that receive regular updates from external accessories
I saw many links in Stackoverflow, but i dnt get proper answer.
Some links:
socket connection killed after iOS app goes to background
iOS application executing tasks in background
https://blog.newrelic.com/2016/01/13/ios9-background-execution/
Can you guys can suggest me how to keep the app in background??
Thanks in advance

What is GCDWebServer for?

I have a problem when loading the local web from WKWebView in iOS8. There are some suggestions that I should use GCDWebServer. I read through GCDWebServer, but not really understand what GCDWebServer is for on mobile application's side.
Could you give me any practical case of using this library? Sorry for my ignorance.
It's a webserver that you can run on your iOS device. Just like you would run a webserver on VPS or dedicated server providers.
This webserver that you would run and host from your iOS app will of course be available only in the network your iOS device is connected to.
This makes it useful for you to write client programs or scripts on other machines but connected to that network, to call your iOS app (running the GCDWebServer) to upload or download files that you so choose to store in your iOS app's sandboxes document directory for instance. Or as simple as viewing HTML or other data - plain text or json - served by GCDWebServer.
It had nothing to do with what WKWebView. WKWebView is a 'simplified WebKit browser client' that you can implement in your iOS app to view web pages served from other webserver hosts.
You can think of WKWebView as the complete opposite of GCDWebServer.
We can use GCDWebServer has a network interceptor in ios. You can intercept any HTTP requests happening inside WKWebView. For example, you can use GCDWebServer to handle caching and parallel processing for your expensive API requests. You can immediately return some cached responses and later redirect the URL to the actual destination.

inspect http requests in ios simulator/devices

I am working on an ios app which communicate with the server via http request. And I want to monitor the network traffic when testing my app in ios simulator/devices.
Is there any software or tools I can used to inspect the http requests of a specified application on mac/ios, just like firebugs for web developers?
Thanks.
As far as I know, there are several tools in App Store that provide the network traffic monitor feature. But, they could only view iPhone as a whole and stay at that level. In other words, they could only tell how much traffic has been consumed of this iPhone. For each app? No data.
You can use HTTP Catcher to capture web traffic. It's a Web debugging proxy for iOS, so you can view requests and responses directly on iPhone.
You can use Proxyman to record/capture all the requests & responses from your app while developing.It will support ios simulators also. Without doing any code change we use this.
First Download the Proxyman app form the above link after that just go through this documentation for references.
Charles has recently released an iOS version for http traffic monitoring. it is a paid app though. Good news is that you can set up Charles free desktop version then setup HTTP proxy from your iOS device.

Resources