how to integrate javascript in iPhone application? - javascript

i am new in iphone application and i want to integrate the javascript so would you please give some information about how to implement javascript?

I don't know what exactly you mean by
i want to integrate the javascript
You have full JS support inside UIWebView. You can inject your own JS code and communicate with the existing JS code.

According to the policy set by Apple on applications for the iPhone, you can not use any interpreted language. Thus, Javascript is unfortunately out of the question.
This is stated in the iPhone SDK agreement.
3.3.2 — An Application may not itself install or launch other executable
code by any means, including without
limitation through the use of a
plug-in architecture, calling other
frameworks, other APIs or otherwise.
No interpreted code may be downloaded
or used in an Application except for
code that is interpreted and run by
Apple’s Documented APIs and built-in
interpreter(s).

Continuing with what Michael Kessler said you can also use javascript embedded in a UIWebView to access native iPhone functionality via libraries such as phoneGap making your javascript more powerful than the normal safari variety.
http://phonegap.com/download
Includes a iPhone project that you can use as a basis for your javascript application.

Related

Interaction between Dart/Objective-C and Dart/Java

I read a really interesting article about how create cross-plateform app : http://www.skyscanner.net/blogs/developing-mobile-cross-platform-library-part-3-javascript
But I would prefer use Dart instead of Javascript, and I was wondering if it's possible to interact between Dart/Objc and Dart/Java (Android), in the exact same way that is showed in the article (run a Javascript VM to execute the javascript code).
Thanks
You can code it in Dart and use dart2js to output JS code then put that JS code in PhoneGap or Cocoonjs to get it on Android/IOS.
The article seems to show how its done with JavaScript. I am sure its possible to code a Dart mobile cross-platform library but it hasnt been done yet.
iOS does not allow 3rd party VMs to be included with your app. The only VM you have access to is the JavaScript VM that is bundled standard with iOS. Even Google Chrome on iOS is crippled in this way (they cannot include v8 on iOS).

How to develop Desktop Apps using HTML/CSS/JavaScript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
First, I'm not interested in doing this professionally. I am a web developer, a coworker of mine recently left for Spotify and said he will be working mostly in JavaScript for the Spotify Desktop app. He said it uses "Chrome frame" and everything inside is done like a web app (HTML/JS/CSS).
As a web developer who never built anything for Desktop, this is great news. If I can use the technologies I already know and implement them inside some sort of a "frame" and still be able to build a windows or better yet cross platform app.
I know I didn't mention anything about the database, but even a simple hello world desktop app with web technologies would be great to get going.
So how does one go about this? Exactly what do I need/need to know?
You may start with Titanium for desktop dev. Also you may have a look at Chromium Embedded Framework. It's basically a web browser control based on chromium.
It's written in C++ so you can do all the low level OS stuff you want(Growl, tray icons, local file access, com ports, etc) in your container app, and then all the application logic and gui in html/javascript. It allows you to intercept any http request to either serve local resources or perform some custom action. For example, a request to http://localapp.com/SetTrayIconState?state=active could be intercepted by the container and then call the C++ function to update the tray icon.
It also allows you to create functions that can be called directly from JavaScript.
It's very difficult to debug JavaScript directly in CEF. There's no support for anything like Firebug.
You may also try AppJS.com (Helps to build Desktop Applications. for Linux, Windows and Mac using HTML, CSS and JavaScript)
Also, as pointed out by #Clint, the team at brackets.io (Adobe) created an awesome shell using Chromium Embedded Framework that makes it much easier to get started. It is called the brackets shell: github.com/adobe/brackets-shell Find out more about it here: clintberry.com/2013/html5-desktop-apps-with-brackets-shell
NW.js
(Previously known as node-webkit)
I would suggest NW.js if you are familiar with Node or experienced with JavaScript.
NW.js is an app runtime based on Chromium and node.js.
Features
Apps written in modern HTML5, CSS3, JS and WebGL
Complete support for Node.js APIs and all its third party modules.
Good performance: Node and WebKit run in the same thread: Function calls are made straightforward; objects are in the same heap and can just reference each other
Easy to package and distribute apps
Available on Linux, Mac OS X and Windows
You can find the NW.js repo here, and a good introduction to NW.js here. If you fancy learning Node.js I would recommend this SO post with a lot of good links.
Awesomium makes it easy to use HTML UI in your C++ or .NET app
Update
My previous answer is now outdated. These days you would be crazy not to look into using Electron for this. Many popular desktop apps have been developed on top of it.
NOTE: AppJS is deprecated and not recommended anymore.
Take a look at NW.js instead.
It seems the solutions for HTML/JS/CSS desktop apps are in no short supply.
One solution I have just come across is TideSDK: http://www.tidesdk.org/, which seems very promising, looking at the documentation.
You can develop with Python, PHP or Ruby, and package it for Mac, Windows or Linux.
Sorry to burst your bubble but Spotify desktop client is just a Webkit-based browser. Of course it exposes specific additional functionality, but it's only able to run JS and render HTML/CSS because it has a JS engine as well as a Chromium rendering engine. This does not help you with coding a client-side web-app and deploying to multiple platforms.
What you're looking for is similar to Sencha Touch - a framework that allows for HTML5 apps to be natively deployed to iOS, Android and Blackberry devices. It basically acts as an intermediary between certain API calls and device-specific functionality available.
I have no experience with appcelerator, bit it appears to be doing exactly that - and get very favourable reviews online. You should give it a go (unless you wanted to go back to 1999 and roll with MS HTA ;)
I know for there's Fluid and Prism (there are others, that's the one I used to use) that let you load a website into what looks like a standalone app.
In Chrome, you can create desktop shortcuts for websites. (you do that from within Chrome, you can't/shouldn't package that with your app) Chrome Frame is different:
Google Chrome Frame is a plug-in designed for Internet Explorer based
on the open-source Chromium project; it brings Google Chrome's open
web technologies to Internet Explorer.
You'd need to have some sort of wrapper like that for your webapp, and then the rest is the web technologies you're used to. You can use HTML5 local storage to store data while the app is offline. I think you might even be able to work with SQLite.
I don't know how you would go about accessing OS specific features, though. What I described above has the same limitations as any "regular" website. Hopefully this gives you some sort of guidance on where to start.
You can build Javascript apps with Adobe AIR… http://www.adobe.com/products/air.html
CEF offers lot of flexibility and options for customisation. But if the intent is to develop quickly node-webkit is also a good option. Node-web kit also offers ability to call node modules directly from DOM.
If there aren't any native modules to integrate Node-Webkit can offer better mileage. With native modules C/C++ or even C# it is better with CEF.

Is it possible writing a cross-platform desktop application with XHTML, CSS and JavaScript?

Is it possible writing a cross-platform desktop application with XHTML (or HTML), CSS and JavaScript?
If the answer is yes, how to run this application? Should I run it with a browser like Firefox?
Note: Currently Windows supports HTML Application.
It seems that what you're looking for is the Open Web Apps
HTA is really Old technology.
Try tools like Titanium (Appcelerator). They are tools, which render HTML content inside an APP. So, from outside, you will be running an executable but inside , it is loading a HTML file.
Same principle is being used in many apps now a days. Facebook for android is a best example
If client-side JavaScript, and/or HTML/CSS hackery accomplishes the task you wish it to, yes, and with a user agent like Firefox, indeed.
Yes. With HTML5.
The other answer's solutions are great, but generally they assume that the user is connected to the internet to have a server-side that handles the data.
But it's possible to use Open Web Apps (as ZER0 suggested) with HTML5, which has a lot of support for offline web apps.
Pay attention to it, though. Even HTML5 assumes that eventually the user will have some sort of internet connection, and offline functionalities are seen as a "cache". So, I'm not sure that this solution is enough for every requirement, because I don't know how much space HTML5 provides to offline applications

Building a Windows app w/ embedded browser & JavaScript 'hooks'

I built a PHP / JavaScript website for a customer. Then they asked me to replicate it except as a standalone Mac application. I did this with an app that combined an embedded web server, PHP, and 'WebView' - a Cocoa-ish version of the WebKit web browser that I can embed in a standard app window. This all worked great - I got to reuse 10,000+ lines of PHP/JS code, which saved months off of re-implementing it all again in 'native' code.
Now they want a Windows equivalent. I'm reasonably confident I can get PHP and the web server to work. And I know embedding basic IE functionality is pretty easy.
However...in my Mac setup, WebView (via the windowScriptObject stuff) gave me the ability to call JavaScript methods from C++. For instance, I might call a JavaScript method from C++ to update the screen. Likewise I could set things up so that a JavaScript call in the browser could trigger a C++ method - I used this, for instance, to let a user click 'BROWSE' and pick a file path using a real, standard file browser.
So my question is, is there a Windows-based embedded browser setup that would let me interact with JavaScript in this same way?
(the JavaScript <--> WebKit interface is described in much better detail here: http://lipidity.com/apple/javascript-cocoa-webkit/)
Maybe try using something like Appcelerator Titanium so you'll be ready when your client says they want it to work on Linux, or iPhone, or Android.
Quoting Wikipedia: "Appcelerator Titanium is a platform
for developing mobile and desktop
applications using web technologies.
[...] Support for standards-based web
technologies: HTML, CSS and Javascript
on all platforms along with PHP,
Python and Ruby for desktop platforms.
Integrated support for popular
JavaScript and AJAX Frameworks
including jQuery, YUI, MooTools,
Scriptaculous and others."
Sounds like a perfect tool for the job.
When you embed the Web Browser Control (IE), your application code can simply call execScript (http://msdn.microsoft.com/en-us/library/ms536420(v=vs.85).aspx) on the window object. You can have your script call out to the application by using the window.external object from the script, and by using the ObjectForScripting (or C++ equivalent) from the application.
maybe Qt will be good for your case, also you have QtScript and can inject javascript with evaluateJavaScript
I found a great example on the web for invoking JS in my embedded browser from C...basically using COM-ish methods that let you get a DISPID from a script object, and then using the Invoke() method with that. This works great.
But it turns out I need to also call C++ funcs from my JS code. It appears this is possible, and after hours of messing around I think I almost had it - it's like the above in reverse - you create a COM object, then hook it to the browser's script object - but in the end I could not close the deal - I kept getting "library not registered" errors. Honestly I don't know COM well enough to do this right.
So then I, for the heck of it, tried building my first C# app. In about 20 minutes I had an app running with a browser where I could both invoke JS inside of it and have the browser invoke C# methods. Geesh. I'm a believer in .NET after this experience, and a confirmed non-believer in 90's Microsoft technology.
In the interest of completeness, I'd like to mention my Windows port of WebKit, which includes the various cross-layer features of WebKit on the Mac.
I posted some example code showing how to embed WebKit in a native WinAPI application, complete with JavaScript->C++ and C++->JavaScript examples.
The example is a tiny test case for a much larger application using embedded WebViews for major UI components. I can confirm that what you are doing is not only possible, but a great way to build an application.

Is Javascript only available for web browsers?

I would like to know about Javascript. Is Javascript available only for web browsers? Because I used some Javascript code for Firefox Plugin development and Thunderbird.
Help me to find out more about this: where can I use JavaScript other than web browsers, and how?
There's node.js which includes a full webserver and runs on Google's V8
No! Have a look at Google's V8
Google Javascript. Click first link (Wikipedia). Click "uses outside webpages".
http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pages
There are a number of server-side (or otherwise non-browser) implementations of Javascript, including Node.js, which currently has a lot of momentum behind it, as well as the now-defunct Jaxer, which provided a server-side DOM implementation based on Mozilla Gecko. There are also efforts to bring DOM type functionality to Node.js, primarily from Yahoo.
With Rhino, you can embed Javascript in Java applications.
No, there are definitely other implementations. For instance, JScript.Net is included with the .NET framework.
MS-Windows can execute .js files (from the command prompt).
Since you do not have the browser context, you cannot use any calls to the browser (alert, for example, does not work).
Look for "Windows Scripting Host".
WSH supports scripts written in
Microsoft Visual Basic Scripting
Edition (VBScript) or JavaScript.
There are several implementations of stand-alone Javascript
JSLibs (http://code.google.com/p/jslibs/) is general purpose
jsdb (http://www.jsdb.org/) is more database oriented
Many text editors (including the one I use, ActiveState's Komodo Edit) expose their APIs and let you write macros in Javascript.
Using Adobe AIR you can write almost platform-independent Desktop Applications using JavaScript
PDF files can also contain JavaScript code. See first entry in google on this subject and also Adobe JavaScript virus.
Javascript can be easily embedded in applications written in other programming languages.
For Java there is as already mentioned Rhino, for C++ you can use for example Flusspferd. Here are some tutorials/examples.
Qt has the QtScript module. From Qt 4.7 it uses JavaScriptCore (the Webkit JavaScript engine).
In short, No.
Actually, Javascript and other Web technologies are used these days to create native mobile and desktop applications. (see Titanium Appcelerator and PhoneGap)
If you are familiar with the KDE project you can craft Plasma widgets using JavaScript, see Creating plasmoids with JavaScript
In Qt framework there is a QtScript module for JavaScript (ECMAScript) application scripting to provide much of the application’s functionality.
Also the new technology that is soon to be released in Qt 4.7 is Qt Quick, aka the Qt UI Creation Kit, which allows application developers to declaratively define their user interfaces in QML, for more information go here and an example here
QML is an extension to JavaScript,
that provides a mechanism to
declaratively build an object tree of
QML elements. QML improves the
integration between JavaScript and
Qt's existing QObject based type
system, adds support for automatic
property bindings and provides network
transparency at the language level.
And let's not forget Javascript is used as an embedded scripting language in various applications OpenOffice.org, Google Desktop Widgets, and many others, see Wikipedia's article here
On the server-side Javascript enables back-end access to databases, file systems, etc (see Node.js, Google V8, SpiderMonkey and others here)
Some document databases, such as CouchDB and MongoDB, use JavaScript to interact with the database.

Categories