PDA

View Full Version : Display variables from app in internal webpage?




ArtOfWarfare
Sep 19, 2012, 08:00 AM
The Story
I'm trying to make a full native app for Android + iOS. On the Android version, I found that to make a view that scrolls horizontally and vertically and can also zoom in/out, it was easiest to just make an internal webpage and display it in a WebView.

I know that with the iOS it wouldn't be too much work to just start over on this part from scratch, but I thought, hey, if I'm already making an internal webpage for the Android version, and both iOS and Android use WebKit, in the interest of easily maintaining both versions of the app, wouldn't it be easier if I just use the exact same internal webpage in the iOS version.

The Question
An issue is, I have very limited experience with web programming (I'm actually viewing this as more of a pro... it means I have a learning opportunity now... I'll have broader opportunities later.) The internal webpage needs to be able to display data that I already have within my app. IE, the app is holding onto an array of 100 or so ints. How can I pass these ints into my internal webpage so that it can reflect them?

To be clear when I say "internal", I mean the HTML files and other resources are stored on device, in the app bundle.



Reason077
Sep 19, 2012, 09:42 AM
The easiest/simplest approach is just have the iOS native side of your app generate the HTML which contains your data. If your data is relatively simple, and you put all your formatting in a separate CSS file, this can actually work quite well.

If you want to do something more sophisticated, you probably need to use JavaScript. Your cocoa touch code could then write out a file containing the data (maybe in JSON format) and the JavaScript side can then load it and insert it into the document.

You can also use [webview stringByEvaluatingJavaScriptFromString:@"...JavaScript code goes here..."] to dynamically update the webview based on events on the cocoa side.