开发者

Ok to implement backend/shared functionality for iPhone in JavaScript?

Is it ok to use the Webkit Javascript engine to implement cross-platform, non-GUI backend functionality on the iPhone, iPad? In my case, I was interested in re-using Javascript code that I have that works on top of SQLite. I thought I would need to re-implement the logic in Obj-C but perhaps I could just share it and expose some hooks into Obj-C using JSCocoa or straight through JavaScript core. If I do this, is it ok to bypass the UIWebView con开发者_开发问答trol and go straight to JavaScriptCore or is that still considered a private framework? I am still searching and will update this if I find the answer.


Although the iPhone uses WebKit, UIWebView does not expose it as a public interface. To strictly follow apple guidelines, the only communication between a web page and the host application is by calling eval with stringByEvaluatingJavaScriptFromString and by processing resource requests.

You can do a lot in javascript. In fact, when it comes to controlling a UIWebView, javascript can often do more than Objective-C. If your communications with the host application are simple enough you should be able to keep your existing code with minimal changes.


I'm pretty sure it is legal, in fact I have done this recently for a project at my company. We had a GWT app which spat out a JavaScript/HTML application which we needed to be port to iPhone and Android. Rather than doing a complete rewrite on each platform, we went down the (slightly insane) route of keeping the Java/JavaScript backend and sticking on native code to handle the UI. Works well and you can't tell that in the background it is a browser that is running the show.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜