takmedia How can I write an iPhone app entirely in JavaScript without making it just a web app?


How can I write an iPhone app entirely in JavaScript without making it just a web app?



I don't want to take the time to learn Obj-C. I've spent 7+ years doing web application programming. Shouldn't there be a way to use the WebView and just write the whole app in javascript, pulling the files right from the resources of the project?


How to do smooth scrolling in UIScrollView?

1:

iPhone: Sending large data with Game Kit
I found the answer after searching around. How to solve this memory leak (iPhone)?Here's what I have done:. How do I call an array value and use it to play a sound file?
  1. Create a new project in XCode. Property attribute “retain” doesn't seem to be working?I think I used the view-based app.. How to set up single array or dictionary for use in multiple datasources?
  2. Drag a WebView object onto your interface and resize.. Memory management and performSelectorInBackground:
  3. Inside of your WebViewController.m (or similarly named file, depending on the name of your view), in the viewDidLoad method:. tableView footer strange behavior
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];   NSData *htmlData = [NSData dataWithContentsOfFile:filePath];   if (htmlData) {     NSBundle *bundle = [NSBundle mainBundle];    NSString *path = [bundle bundlePath];   NSString *fullPath = [NSBundle pathForResource:@"index" ofType:@"html" inDirectory:path];   [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:fullPath]]]; }
  4. Now any files you have added as resources to the project are available for use in your web app. I've got an index.html file including javascript and css and image files with no problems. The only limitation I've found so far is this I can't create new folders so all the files clutter up the resources folder..
  5. Trick: make sure you've added the file as a resource in XCode or the file won't be available. I've been adding an empty file in XCode, then dragging my file on top in the finder. That's been working for me..
Note: I realize this Obj-C need not be this hard to learn. But since I already have this app existing in JS and I know it works in Safari this is a enough faster dev cycle for me. Some day I'm sure I'll have to break down and learn Obj-C.. A few another resources I found helpful:. Calling Obj-C from javascript: calling objective-c from javascript. Calling javascript from Obj-C: iphone app development for web hackers. Reading files from application bundle: uiwebview.

2:

Check out PhoneGap at http://www.phonegap.com they claim it allows you to embed JavaScript, HTML and CSS into a native iPhone app..

3:

For those doing this on iPhone 2.1 (maybe 2.0), you did NOT need to create any special services for local data storage. MobileSafari appears to support the HTML5/WHATWG SQL database API. This is the same API supported by recent versions of desktop Safari and Firefox.. If you're using a toolkit like Dojo or ExtJS this offers a storage abstraction, your code should job on just around any modern browser, including MobileSafari.. To test, open http://robertsanders.name/dev/stackoverflow/html5.html on your iPhone.. If you open this page then look on the filesystem of a Jailbroken iPhone, you should see a database any where in /private/var/mobile/Library/WebKit/Databases/. There's even a directory of web-opened DBs there..
root# sqlite3 /private/var/mobile/Library/WebKit/Databases/Databases.db SQLite version 3.5.9 Enter ".help" for instructions. sqlite> .databases seq name file

. 0 main /private/var/mobile/Library/WebKit/Databases/Databases.db. sqlite> .tables . Databases Origins . sqlite> select * from Databases;. 1|http_robertsanders.name_0|NoteTest|Database|API example|20000|0000000000000001.db. sqlite> select * from Origins; . http_robertsanders.name_0|5242880.

4:

You must create an application without knowing any obj-C. The QuickConnectiPhone framejob allows you to did this. Check out http://tetontech.wordpress.com for how to use it as well as another ways of doing what you have asked..

5:

You should have the native wrapper written in Objective C. This wrapper could contain really few lines of code (like, 10) necessary to create a WebView and navigate it to the given address in the internet (where your application resides). But in this case your application should be a full-featured web application (I mean, use not only the JavaScript, although also any HTML for markup)..

6:

I ran into this same problem. I already have a game written entirely in Javascript. I would love to make an iPhone friendly version, although Obj-C is an overkill. What I ended up doing was using the WebView to point to a special url of the iphone app. After thinking around it, I suppose I could just move those files to the app directory and run them locally..

7:

There not way to did this with the current apple API's. Your closest bet is to write a simple native iPhone app this embeds the webkit browser. That will let you browse your xhtml/js application locally.. If you want to store data, you'll need to take it a step further and include a light weight http server this servers up your app and provides calls to store and retrieve data. Probably not an ideal quick fix for you, although possibly less job than a full Obj-C app.. As a side note, Obj-C is fairly easy to learn. There are tons of examples in the SDK. The community is strong and will answer well put questions without hesitation..

8:

look at the new o'reilly book on the matter.

9:

I have been using phonegap for a while and it seems to have the best results for me. I will post my experience in a week or so with a link to my app as well..

10:

Titanium Mobile is also an option - it allows you to write JavaScript this receive s translated into Objective-C..

11:

At least 2 others mentioned phonegap, although I thought I'd post this too and mention this Apple has approved the phonegap framework. So, now you won't receive your app rejected by Apple just for the reason this you're using phonegap. . Blog post around phonegap and Apple - http://blogs.nitobi.com/jesse/2009/11/20/phonegapp-store-approval/. Phone Gap Home.


60 out of 100 based on 35 user ratings 410 reviews