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 control 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.
-
1Questions like this make me very sad. Oh Apple, what have you done...Matti Virkkunen– Matti Virkkunen2010-05-11 16:54:34 +00:00Commented May 11, 2010 at 16:54
-
Matti, to answer: created one of the most profitable and powerful opportunities for developers ever. Did developers ever make money on mobile before Apple. Uhh, no. Ok back to my question.John Wright– John Wright2010-05-11 17:02:48 +00:00Commented May 11, 2010 at 17:02
-
@John Wright: I take it their TOS now requires developers to post defensive comments about their draconian policies, lest their apps all mysteriously disappear and any iPhones in their possession explode?Matti Virkkunen– Matti Virkkunen2010-05-11 17:07:34 +00:00Commented May 11, 2010 at 17:07
-
@John Wright: Yeah, Steve Jobs sure is the creative genius of the century ¬__¬Matti Virkkunen– Matti Virkkunen2010-05-11 17:23:20 +00:00Commented May 11, 2010 at 17:23
-
Is it OK? Assuming you are talking about in relation to the updated SDK Agreement, probably. Is it going to be a good longterm solution? I don't know. It is quite possible that Apple could be wise to your "scheme" and reject your app for minimal functionality. Personally, I think you may be playing with fire.bpapa– bpapa2010-05-11 17:42:56 +00:00Commented May 11, 2010 at 17:42
2 Answers
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.
1 Comment
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.