View local html/js contents in mobile safari - ios

I need to view some local (saved somewhere in the iPad) html / js contents with mobile Safari. By reading some threads it seems that the file:// protocol is disabled. Right?
If so, the solution I see is to install an app which turns the iPad into an http server (no need for support of php or anything else), load my contents there and access somehow them within the same device by http://localhost/... or http://127.0.0.1/... with mobile safari.
Is that actually possible? Can someone please suggest me a good web server app which possibly does not require jailbrake or other hacking?
Thanks!

You probably can't do what you want because in order for your application to be serving up HTTP requests to Mobile Safari, it would have to be running in the background, and there's no permissible background mode that covers this.
If you only need a one-time-only response immediately after running your application, then you could possibly use beginBackgroundTaskWithExpirationHandler:, although this might not be approved by Apple - it's difficult to predict their response to that.
If you are sure that you don't need this to go into the App Store, then you can get your application running in the background permanently by abusing one of the other background modes, such as pretending to be a VOIP app or media player.
Once you're running in the background, you can use CocoaHTTPServer to actually serve the files.
If you describe what you are trying to achieve, somebody might be able to suggest an alternative approach to using local files / Mobile Safari.

Related

Record audio in mobile Safari

I need to create an iOS app that just displays a website. The site allows users to record audio. The purpose is to let mobile Safari users to record audio (which is currently not supported). Are there any decent solutions for this or am I going to have to hack my way through? So far I have the following two ideas:
1) Build a native application that contains a WKWebView of the site. If the website detects mobile Safari it will launch some JavaScript that the app can respond to (or it will try to bring the user to the App Store using Universal Links). The native app will then record the audio and send it back to the website somehow (either through an external server, or perhaps through JavaScript, not sure how much data can be passed, but it could be up to 1MB).
2) Use an existing solution using perhaps Cordova/PhoneGap.
Hope to get some tips!
Build an hybrid application based on cordova/PhoneGap seems to be the best in my opinion. In addition you can build for iOS and Android (if you need later).
You can easily use this plugin to achieve your app.

iOS 9 - open resource in web browser on another computer, triggered by tablet

If you had to open a resource from a database in a web browser on another computer, using an Apple tablet app as a remote control, how would you implement such a feature? This is basically what WhatsApp Web does, so it should be technically possible. But how would you go about it?
I'm assuming that you mean a situation where the app modifies something on the server, and the browser then updates automatically to reflect this. If you mean something like the iOS Remote app, then you may have to use another method (and you may not be able to do it from the browser).
To do this you'll have to have a server that both the iOS app and the browser are connected to. When the app does something, it updates the server, e.g. by submitting an HTTP request to a REST API. The server then updates the database.
Now you have to get the browser to update, and there are two ways of going about this. One is by polling the server periodically, using AJAX to update parts of the page dynamically without refreshing the whole page. This works, but there's a lot of overhead and it can be a drain on a laptop battery.
The better, but slightly more difficult to setup, alternative is to use WebSockets. WebSockets allow for two-way communication between server and client, and the connection stays open until one party closes it (or it times out after a long time). The client can submit information to or pull information from the server as before, but the server can also push information to the client without the client having to request it. This would typically be how games, chat clients, etc. can operate nearly in real time.
Setting this up isn't necessarily that difficult, but it's a very broad, open-ended topic that's beyond the scope of just iOS development. Beyond the iOS app and the web client, you'll also need a backend that's capable of using sockets. Node.js is a popular JavaScript-based backend for this sort of application; there are numerous others out there as well. You'll have to do your own research to determine what's right for you.

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.

View get requests being made by an iOS app

Is there any way to view the get/post requests being made by an app from a users perspective?
I figure I won't have to worry about cross site request forgery if there isn't any way to view the requests going back and forth from my ios app to the server and it could potentially save me a lot of work. But at the same time I don't want to sacrifice security.
If there is a way to view the requests. How would you do it? Can I hook up a sniffer to my iPhone or something? If this isn't too difficult I would be interested in playing around with a couple of other apps (bwahahahaha)...
I use Charles for this purpose. http://www.charlesproxy.com/
You set it up on your computer and then set your iOS device to use it as a proxy. It will show you all network traffic and is easy to use. You can also pass back different information if you want to simulate a server that isn't running yet.

Is there any way to have a web page record sound from an iPad?

I don't think this is currently possible with straight HTML (although I've heard that HTML5 may support this in the future):
I'd like a web app that can record audio from the iPad (and also, ideally iPhone).
This will not be an iOS app. It's a web page.
Unfortunately, no. The only hardware functions you can get access to via HTML/JS are the location service and the accelerometer.

Resources