Accessing UIWebView local storage data from native iPhone app - iphone

I'm writing a native iPhone app that contains a UIWebView component. This component accesses an internet webapp and the webapp stores data offline using HTML5 local storage.
Is it possible to access this local storage data from the native app ?

I was looking to do something similar to this. In short, the DOM and all elements are not directly accessible. However, you can hack things up to get at the data. What you have to do is inject your own javascript into the downloaded webpage. Then evaluate the results.
This page shows the mechanism for doing it:
http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview
Then you just need to know the name of the database and create some javascript to return the values in a JSON string. Use a cocoa JSON parser to create objects from that string that you can use in your native app.

Related

Dynamic Content using Xcode

I am relatively new to creating apps, I noticed on some apps that there are images or content that will change with our the app having to be updated, how is this achieved? I have been looking everywhere I could think of and have came up empty.
Thanks for any advice.
As Michael mentions you can use a UIWebView and UIImageView to render the contents of a particular URL. However, most dynamic content on the iPhone is achieved using web services rather than directly rendering a web page.
If you are not familiar with web services, you can think of them as a stripped-down form of content; they are the link between the database and the client. In this model, the client requests data from the web service, the web service fetches from the database, and the client renders the web service response as he sees fit.
For example, you can use a JSON-based web service to return content like {"Movie":"Title","Review":"Pretty good"} and create a content view with two UILabels, one bigger and one smaller, to reflect this:
movieLabel.text = [[JSONParser parseString:[WebServiceClient JSONForRequest:&request] movieString];
reviewLabel.text = [JSONParser parseString:[WebServiceClient JSONForRequest:&request] reviewString];
Read more about web services and iOS at http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service
These are typically apps that get their resources via URL references to servers providing content (graphics, images, the latest "sale" page or whatever).
Many iOS classes (such as NSData or NSString) have initializers like initWithContentsOfURL:encoding:error:. Other classes (like UIImage) can be easily instantiated with data downloaded from a URL (imageWithData).
You can also embed web views (UIWebView objects) into your app and simply point that web view at some convienent URL on your server.
Apps can request data from a remote server and download it to the app. You can use classes in URL loading system to interact with remote servers. Here is a [link] http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/URLLoadingSystem/Concepts/URLOverview.html for further reading.

Package webdatabase in phonegap

Phonegap storage documentation speaks only about how data can be added to the app via code. I want to push a compiled database (say Directory of phone numbers) to the PhoneGap app. Is it possible?
AFAIK, you cannot push a compiled DB.
What you can do is to include the content of this database as a SQL file in your app, load it in ajax and use phonegap executeSql function to populate the DB.
This would of course only need to run once.
You could also just export the DB to a text format (CSV or JSON), and depending on the size and how/what you are querying, either load it in memory or add it to the localStorage (or SQL) in the target PhoneGap framework...
The only other way I see this happening is by using CouchDB - a NOSQL DB that has support for Android/iOS/PhoneGap - which can also synchronize a local DB with a remote one (all magic!) thus allowing your remote phone numbers to change and still to be updated (incremental) at your client.
Hope this helps

iPhone Online DB Question

My question deals delivering information to iPhone devices via an online DB. (Essentially, I want to do something like the NYTimes App, which provides the latest news for each device containing the app). I know I need to use a SQL lite database to accomplish this. What is the best way to approach this problem? I am a newbie at this stuff, so I'm not sure exactly where to get started? Do I need to create an online DB, or can I update outstanding apps from a local SQL database?
Thanks in advance!
Vineet
For connecting to remote databases for getting data you will have to send request from iphone either in XML or JSON format.
If you are using XML, then use NSXMLParser for parsing the XML file sent as response from the remote application. Better option would be to go for JSON.
You need to create a web application which should return a data to iPhone over http protocol.
I think I've done something similar a while ago.
I created a simple PHP API which returns the posts from a blog in JSON form. Then in the iPhone app I make an API request, parse the resulting JSON string and setup a UITableView with the stuff I retrieved from the database. In this way you don't query the database directly, it's the PHP script that does it.
You could also use XML instead of JSON, of course. If you end up using JSON, you can use this library to parse it in your app.

How do I create a development tool to create custom object instances for iphone os

I'm setting out to create an app where it will use 7-10 instances of a custom class, lets call them "books" each class will consist of a number of pages, a title, a int of how many pages a book contains and possibly some notes of the author associated with a specific page.
My question is what is the best way of creating these objects. it seems weak to just hard-code all the books together programatically, and if there are more added after the initial release I'd almost like to have the author be able to construct them with a simple desktop app.
So I guess what I'm looking for is a way to a create a small app to create instances of a custom class on a desktop, then bring those instances into the iphone app.
I only have an iphone dev license as far as I know. Obviously you don't have to be super specific but I'm looking for ways to accomplish this type of task. Maybe if there is a good way to go about hard coding them I would like to hear about that as well.
I guess an equivalent would be a game developer making like a level editor for his game so he doesn't have to create the boards programatically.
Provide your data in XML or JSON
format (or whatever flavour of file
format you prefer), this is to transfer data to/from application.
Parse your data file (xml/json) and store in permanent storage (file,sqlite,core data) on phone. This is the data that your application will regularly use from now on.
Offer user the option to get updates over network
If user selects to get updates, download updated xml/jason file over network, parse and update your permanent store
Use SQLite. You could easily create a sqlite database editor, or use some of the free ones out there. The iPhone can read a sqlite database natively, just include the library.

Obtaining information from Webpage - displaying it in an Iphone app

Is it possible to pull information from a website and display it in an iphone application?
I am looking to pull the current temperature and barometric pressure for an airport from the http://adds.aviationweather.noaa.gov website and display those two pieces of information in an app.
This sounds like a common task that programs do all the time but I'm not sure how it's incorporated into an app.. (what is the process of pulling webdata called?)
What methods or tools are available to do this? I am unfamiliar with handling web data for iphone at this time.
If they have an actual feed for the data, you could access it using NSHTTPRequest and parse the results.
If you need to screen-scrape the data off the page itself, then I would highly suggest creating your own web service to do the parsing and have your iPhone app talk to your web service. The reason being that if they update the page in a way that breaks your screen scraping you would only have to update your web service instead of deploying an update out to who-knows-how-many iPhones.
Just use an NSHTTPRequest and all the related classes to assemble a standard HTTP GET request for the site with the data you need. If there's a data feed (XML, JSON, etc.), you should find out what that URL is and use it instead of parsing the actual HTML of the web page. If not, the method is called "screen scraping" and it basically involves you writing a regular expression to parse the HTML of the web page returned from the server. Again, don't do this unless there is no alternative data feed you can use.
If you need to parse XML, see NSXMLParser. There are open-source solutions for parsing JSON in Objective-C. Just Google around for them.