iPhone: Native App with Locally Stored Webapp?
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 c开发者_如何转开发an be sold through the app store.
Thanks, ~J
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.
I don't see why not, just give the UIWebView a baseUrl of your local stored bundle.
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.
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.
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.
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.
If you are not a coder and you are interested in iOS only, you can follow these steps:
- Download xCode
- Download simple web view app from https://github.com/nomtek/iOSWebViewApp
- Open simple web view app within xCode
- Add your HTMLs to the project file structure
- Run your app and voila :)
This approach is good if you don't need access to any phone specific features, just a standard Web View. Loading time will be short as this approach doesn't load any extra libraries.
精彩评论