Showing dynamic web-content from iOS local server (i.e. using browser as remote screen) - iphone

I want to show some really simple graphics in a http-page in the local network using an iOS App as local server.
Now I heard showing some http-page over the local network is quite easy, using for example CocoaHTTPServer.
Would it also be possible to adjust the content of the page dynamically, from the iPhone side?
Meaning
user types in URL at the desktop-pc-browser of his choice
user goes to his sofa, flicking through text/images with his iPhone, looking at the remote screen
(no need to go to the browser to refresh page?)
Would this be feasible?
Of course I could also try to set up some Bluetooth-Connection, connecting between iOS/MacOS Apps, but I figured the browser version would be much more flexible :)

Stable connection? No need to support each and every browser? Then open up a websocket connection between your app and your browser. You’d then advise your browser to reload or show another picture through the websocket.
If you need to support more browsers, you might need comet / long-polling support. I’m not sure, though, whether CocoaHTTPServer supports it.
If none of these work, you could have your webapp do an Ajax request every now and then, in order to check whether something has changed.

Related

Can PWA share state/data between browsers?

If I have multiple browsers, can PWA share states or data? For example if I’m offline and I interact with the app on Firefox, save some data, etc. Can I access that same data when I open the app in Chrome? I tried it with https://voice-memos.appspot.com/ but it doesn’t work. Perhaps an unimplemented feature?
No, you can't. The browsers implement the cache in different ways, they store the data in different directories, etc..
Browsers have their own private storage for web apps, and there's no API designed specifically for direct, seamless cross-browser data sharing, so only workarounds are available.
When online you can share the data by synchronizing it via a server. This may even be near-realtime with the help of SSE/WebSockets or push notifications.
When offline I don't think you can in any sensible way. You could instruct the user download a file in one app and select it in a file picker in another app (or use drag'n'drop or copy'n'paste). Maybe (I haven't tested) you could establish WebRTC data connection between browsers while online and it'd survive going offline if the direct p2p connection was made over loopback/LAN.

Running web files inside an iOS App

I'm working on a project that will need to be inside an iOS app as well as a website. It will need to run inside the app since it will must be accessed without a wireless connection.
Is it possible to run my web files inside the app without using something like phone gap?
What is the web connection for? Is it for user authentication? Is it for parsing data from a website? It really depends what you need an internet connection for, if you need some external data from a website or database then you would need to internally create some stores/sqlite db's to hold the data and sync that data when there is a connection.
If you are just running a client side app that you decided to create in HTML then I'd still use Sencha Touch, then Cordova to get it to compile natively.
You can always "Add to home screen" from Safari, to make it run locally. To do this, just visit the webpage when you have internet then add it to the homepage, it will run fullscreen without an internet connection; it will work fine offline IF AND ONLY IF you don't need to connect for any data.

Access smartphone sensors / address book from web app TODAY?

I want to give web applications running on foreign servers access to smartphone sensors and address book data. The W3C is working on a spec for that, called the Device APIs. However, it is not finished yet, and it will probably take quite some time until browser vendors provide working implementations.
But I need this functionality NOW (for a proof of concept). I do not care about portability, Android would be enough. Requiring the user to install special software first would also be OK.
Two solutions come to my mind:
Hack the APIs into the browser myself. Maybe I could take Phonegap and easily write a browser wrapper with it? That is, build a browser with Phonegap that exposes the Phonegap JS APIs to arbitrary sites (don't care about security for now)?
Write a server and run it on the smartphone localhost. This server would provide access to the resources via HTTPS and OAUTH2 (for example). Web applications could then reference this localhost server in their code (HACK HACK .. are there security mechanisms that prevent an arbitrary site from accessing a server running on localhost?).
Suggestions welcome.
Use a WebView:
http://developer.android.com/reference/android/webkit/WebView.html
This class is the basis upon which you can roll your own web browser
A WebView has several customization points where you can add your own behavior. These are:
Adding JavaScript-to-Java interfaces
with the
addJavascriptInterface(Object, String)
method. This lets you bind Java
objects into the WebView so they can
be controlled from the web pages
JavaScript.
You'd need to create an application that acts as the browser, (by implementing a custom WebView). Then in that application, create a java object for the web view that will fetch the sensor information. In the server output, write javascript that tests for and accesses this object.
For android, I believe you can expose custom local functionality to javascript either by wrapping a webview in your own lightweight "browser" application or by building a plugin for the supplied browser. As pointed out in this question How to develop plugins for the native Android browser there is an example in the sdk samples.
But I for one would be rather upset if you enabled a website to access my device's contacts, and would probably refuse to install your application on my device.

How do I upload files using http/ftp to iphone/ipad? (Eg. ifile, goodreader)

Is there any good advice on uploading files to the device? I've seen many apps create a http server on 80 or 8080 to upload files. Does that mean I have to implement a server too?
Are there any 3rd-party libraries? (Preferably open-source and non-GPL)
EDIT: I am going to upgrade files in the app for specific devices in a corporate environment, so the ipad pulling files from a central server is also an alternative. But I would have to send messages to these ipads to tell them to fetch those files.
But I would have to send messages to
these ipads to tell them to fetch
those files.
Push Notification Programming Guide
Or mail with custom URL scheme for launching your application.
iOS Application Programming Guide - Implementing Custom URL Schemes
I assume what you want is a kind of automatic update. An app do something by order from server without user's manual operation.
I don't know enterprise-license specific feature of iOS. But I believe there's no such enterprise-specific APIs. And as I know, automatic update is almost impossible. Because,
There is no system-level support for automatic update. (yet?)
So messaging and fetching feature should be implemented in app.
But no app is guaranteed to run in background for long time.
And also user can turn off any app at any time.
There is no way to send message to an app which is not running.
Even you can send, there is no way to address each client form the server.
If your app is running, sending message or commanding them to fetch or do anything is just a simple work. The problem is there is no regular way to force them always keep alive. Even under situations like OS reboot or abnormal termination.
However there is an alternative. Just registering app as VOIP app like Skype. OS does not keep the app running too, but will monitor specific socket port, and will wake your app when the socket receives some message. For more details, see here: http://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH5-SW15
In AppStore, an app using VOIP for other purpose like automatic update will not be passed, but you have no need to concern about it.
And other way to send message to device without running app is push notification. This is a feature supported in system-level. But this is not designed to commanding app. This is designed to send textual message. So If your app is not running, the message will be displayed to user. However, you can guide the user to start the app by sending push notification.
As a final option, you can request some feature to Apple for enterprise environment. If your company is big enough to get an enterprise license, Apple will consider your feature request seriously.
If you decided to use VOIP method, I'm sorry I can't help you any more. I have no experience of implementing this kind of app. But it should not so hard.
However hard part is server. It definitely require custom server program which keeps TCP/IP connection. Regular HTTP server cannot be used. Because HTTP itself is designed as not to keep TCP/IP connection. You have to build this kind of server yourself from scratch. You'll have to handle lower level TCP/IP transmissions.
There are a few solutions(both of free/commercial) for this kind of server, but none of are popular because this kind of server regularly needs full customization. So there's nothing to re-use or share.
However I believe this is most suitable implementation for your app.
If you can satisfy automatic update only when the app is running, you can archive it by polling server status from the client periodically.
This is easy to implement because you can use regular HTTP servers for this. Client connect and download recent updates from central server periodically. If there is a new update, just fetch and do what you want. And the app is launched, just check the update at first. Prevent all operation until update applied.
This is regular way. Most of applications are built with this method. In this case, you have no need to implement server or hard thing.
However applying speed of update is depend on polling period.
(Edit)
I couldn't care about private APIs. Because your app is not for AppStore, so you can use private API's freely. (This is different thing with jail-breaking. There are so many hidden features by excluded from documentation) I don't know about private APIs, but it's possible there is some API which enable the support for keep-alive of the app.
However, this reverse engineering work is so painful unless you're born to hack.
You may try to use the following open-source in your project:
http://code.google.com/p/cocoahttpserver/
https://github.com/robin/cocoa-web-resource/wiki
Apple has some sample code on their website that details exactly what you're looking for:
http://developer.apple.com/library/mac/samplecode/CocoaHTTPServer/CocoaHTTPServer.zip
So you have a couple options:
You could distribute your app wirelessly within your organization and push new content out as app updates. Apple provides this option to their Enterprise Developers.
Wireless App Distribution
iPhone enables enterprises to securely host and wirelessly distribute in-house apps to employees over Wi-Fi and 3G. Apps can be updated without requiring users to connect to their computers. In-house apps can be hosted on any web server accessible to users. Users simply tap on a URL to install apps wirelessly without needing to connect to their computers.
The alternative is you configure the app to fetch the updated data. You describe adding an HTTP server to the iOS device, but there's no way the server can receive data when the app isn't running. Given your needs, it would probably work better to embed a web client in your app instead.
If I was in your shoes (and option #1 didn't work), I'd use ASIHTTPRequest to check with a server at launch/daily. If there are new updates, the app could then either prompt the user that there are new data files to download, or it could just silently download them in a background thread.
UPDATED: Perhaps I should have been more explicit about how to do #2. You can configure the download so it isn't interrupted when the user quits the app (you don't need to do a Voip hack). Check out the Completing a Finite Length Task in the Background section in the iOS Programming Guide.
There are http server sample codes from Apple and open source community such as cocoahttpserver TouchHTTPD.
You can upload file to the http server on iphone.
Here's a blog and screen-shots about running cocoahttpserver and upload file to iphone.
The Python CGIHTTPServer allows you to create a server in 0 lines of code:
jcomeau#intrepid:~/rentacoder/bin2txt$ python -m CGIHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
Actually implementing a script to parse the input and save the file would take a little more effort.
[later]
OK, so forget about that, Apple doesn't allow it. See Local server on iPad for the iPad at least.

A caching solution for iPhone application

What I'm building is simply an application that fetches data over the web and displays them on the iOS views. Data are text and, sometimes, images / music files / movies.
I'd like to use some caching solution for the media. What it needs to do is:
get an url of the file
check if it's alredy downloaded in the cache storage, if it is, serve it
if not, download it
while also checking how much of the storage the current cache uses, and, if it's over the quota, delete oldest files
Best would be to have a simple interface for this - so I can just give an url and get the file of it (while files can change over time and reside on the same URL, so this should be handled too, in a perfect case).
Anyone knows a library to do it, on iPhone/iPad application?
ASIHttpRequest has a DownloadCache option that may work for you. From their documentation:
* You want to have access to the data when there is no internet connection and you can't download it again
* You want to download something only if it has changed since you last downloaded it
* The content you are working with will never change, so you only want to download it once
This is what I used in my iPad app and it works pretty well.
You could try looking at using a UIWebview for the view. If I am understanding this correctly, you will be hosting your content on a web server and would simply like the iOS device to pull the content from the URL. This is what UIWebview is. It is essentially programmable access to Safari.