NimbleKit - fast iOS app development

Using NKit.js in external page

Problem discussions

Using NKit.js in external page

Postby tikonen » Thu Jun 21, 2012 8:27 am

Is there some way to use NKit functions in externally loaded pages?

We've pretty complicated webapp that needs to be wrapped, and I really want to avoid rewriting templating, localization, navigation logic etc.. so as workaround I tried to redirect wrapped browser to my apps landing page from apps main.html.

main.html (in wrapped app):
<html>
...
<script type="text/javascript">
window.location.href = '<my web app url>'
</script>'
...
</html>

And then in my web apps main page I included NKit.js as standard Javascript file and hosted that on the server.

This seems to work otherwise, but all calls to NKit functions just hang. I guess its because those calls map to CallNKitAction that does XLRH POST request to localhost:30001 and something breaks (same origin policy error?) as page is loaded from external source. However, from nimblekit docs it says that same origin policy is not in effect on wrapped apps.

Any ideas?
tikonen
 
Posts: 3
Joined: Thu Jun 21, 2012 5:39 am

Re: Using NKit.js in external page

Postby eras3r » Mon Jul 02, 2012 10:27 pm

You can't. A way would be loading the external page as WebView into your main.html (or wherever within bundled HTMLs).
Prepare the external page like a bundled one (same NK.js, metadata, etc etc) then all the events called from it will affect your NK application.
I noticed in some cases NK methods don't respond directly. In this case prepare a bridge function in this way:

webview from server:
Code: Select all
function bridgeFunc() {
NKExecuteJavascriptOnPage("realFunction()", "main.html");
}

main.html
Code: Select all
function realFunction() {
NKMoveToPageAnimated("NKpage2.html", "FlipLeft");
}


Eras3r
User avatar
eras3r
 
Posts: 169
Joined: Fri Nov 20, 2009 10:53 pm

Re: Using NKit.js in external page

Postby LTDdev » Thu Jul 05, 2012 6:44 pm

You could copy the contents of NKit.js to the web page as a <script>. Although I don't know if it's legal...
LTDdev
 
Posts: 19
Joined: Wed Feb 23, 2011 1:09 am


Return to Troubleshooting

Who is online

Users browsing this forum: No registered users and 1 guest