views:

124

answers:

6

Is it possible to write a webapp, then embed it in a native app so it can be launched without data and sold through the app store?

The Pre makes it easy to reference files in the local file structure, so it's very easy to build a webapp (HTML, CSS and Javascript) and embed it into a native app.

Is it possible to take the same plain HTML, CSS and Javascript (no Mojo/Webos-specific code) and embed it in the same way into a native iPhone app? This would make it seem to the user as if the icon in the home menu launches a webapp, but the app can be accessed without any data and can be sold through the app store.

Thanks, ~J

A: 

I don't see why not, just give the UIWebView a baseUrl of your local stored bundle.

Tegeril
A: 

Look at PhoneGap (http://phonegap.com/)

I haven't used it but it may be a good solution for what you're trying to do.

dmercredi
A: 

Yes, it is perfectly doable. You just need to build the absolute path to your HTML files within your application bundle, using "file:///" as the protocol, and point the URL of a UIWebView to it. You can do a quick and dirty test using the iPhone OS simulator and writing something like "file:///foo/bar.html" on Safari.app, provided that HTML exists, it will load just fine.

Julio Gorgé
A: 

The problem is packaging it. From what I can tell (and i could very well be totally wrong), apple just dumps all your files into one resources folder, regardless of directory structure in your project. So if you create a webpage that references images/logo.png and javascript/script.js, suddenly those files will be located in / instead of their respective folders. Given that, it might be feasible to create a web app with a completely flat structure from the start.

msfeldstein
That's not correct. You can maintain your complete directory structure by including the directory itself as a resource in Xcode. I do this to provide in-application HTML-based help, with subdirectories for chapters and subdirectories within those for images.
Brad Larson
A: 

There's no technical reason I know of why this should be problem.

However, there's always the chance that Apple could reject the app for doing something like this — they certainly haven't been shy about rejecting apps for not "behaving properly" before, and web apps have some certain peculiarities which make them not feel like native apps.

Such a rejection could probably be resolved by resubmitting, since there's certainly no standard for this kind of thing, but it's certainly something to be aware of.

Matt Ball
There are many apps that do this on the store, however.
Kenny Winker
True, there are lots of apps that use embedded WebViews. However, *I* don't know of any that consist **solely** of a WebView. At the very least, most of those apps will use a native control for the top bar or something, with a massive WebView for rendering content.But like I said, unlikely it would get rejected, but not impossible.
Matt Ball
+2  A: 

Within my application, I have a complete HTML-based manual that I use a UIWebView to display. The HTML, CSS, and images are all stored locally in a Help directory within my application bundle. I simply load the first page using code like the following:

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Help"];       
NSURL *helpURL = [NSURL fileURLWithPath:[path stringByAppendingPathComponent:@"helpintroduction.html"]];

NSURLRequest *URLReq = [NSURLRequest requestWithURL:helpURL];
[webHelpView loadRequest:URLReq];

and everything loads and displays as if it were on a remote server.

To preserve the full directory structure of your HTML, etc. files, simply add those files to your Xcode project, dragging in directories where you can, and add a new Copy Files build phase. Make the destination Resources and the path whatever you want to use for the base of your web files (Help in the example above). Finally, drag all of the HTML, etc. resources you added to your project into this Copy Files build phase so that they end up bundled with your application.

I see no reason why this wouldn't work with more complex web applications, and I've seen no action by Apple against people doing this within their own applications.

Brad Larson
So this would work to extend the method used by: http://bit.ly/4YYzW So that I can have references to images and scripts in a directory structure in my webapp? -- Thanks for this awesome answer, by the way. I'm just new to iphoning and trying to make sure I'm coming at this problem from the right angle. ~J
Jordan
Yes, it should. Their assertion that you can't have subdirectories is wrong. In the example I give above, I have many subdirectories within the Help directory, and everything loads correctly. I've never worked with PhoneGap before, but if everything it produces can be read off of a web server, there's no reason it can't be loaded locally from within your application's resources.
Brad Larson