+40 745 232 788

Online Solutions Development Blog   |  

RSS

Why MoSync could be a better alternative to PhoneGap

posted by ,
Categories: Mobile Development
Taggs , , , , , ,

Developing mobile applications using HTML5 is a very discussed subject these days. Using only HTML, CSS and JavaScript sounds attractive to a lot of people because of the lean learning curve and the cross-platform ability.

Two of the frameworks that make this happen are MoSync and PhoneGap.

The open-source MoSync Software Development Kit (SDK) is a rich cross-platform mobile application development environment that makes it easy to develop apps for all major mobile platforms from a single code base. The SDK enables mobile developers to build and compile apps for up to nine different platforms at once, using C/C++ or HTML5/JavaScript, or a combination of both to create hybrid apps.

PhoneGap is an open source framework for quickly building cross-platform mobile apps using HTML5, Javascript and CSS. Building applications for each device–iPhone, Android, Windows Mobile and more–requires different frameworks and languages. PhoneGap solves this by using standards-based web technologies to bridge web applications and mobile devices.

From these descriptions MoSync stands out by two things: single code base and C/C++. The latter may not be a deciding factor for some but is certainly a great feature as you’ll see if you really want to build truly cross-platform hybrid mobile apps.

For the rest of the article I will present to you the most important issues you might encounter while using PhoneGap and how MoSync could solve them.

PhoneGap’s shortcomings

1. Different projects for different platforms

With PhoneGap for each platform you have to maintain a different project. The burden for that increases when there is a need to use multiple PhoneGap plugins because you need to search and update different files on each platform.

2. Different JavaScript files on each platform for PhoneGap itself and plugins

One of the reasons to choose to create HTML5 mobile apps is having the same code base for all the platforms. Most of the code is the same for all of them, but when it comes to PhoneGap’s JavaScript files and its plugins they are different in each case.

When frameworks like Sencha Touch are used and you have only one bootstrap file (index.html) the issue above can be easily handled by maintaining only different versions of this one file. When using jQuery Mobile we could have more than one bootstrap file so more differences.

A solution for this problem could be to include the files dynamically, a solution which worked for me.

3. Inconsistent plugins code

If some functionality is not available in PhoneGap there is a chance that you will find a plugin that does the trick. The problem with this is that some of the plugins that have the same functionality are not consistent between platforms and most of the time you either use them enclosed in if statements for specific platforms, either you write wrappers to create a unified interface.

An example for this is represented by the Push Notification plugins which work differently. For Android I ended up doing something like this for registering a device:


window.GCM.register(Config.gcmProjectId + '', 'TApp.app.onGcmEvent', function () {
//console.log('Success to register GCM. Waiting for token now.');
}, function () {
//console.log('Failed to register GCM because: ' + JSON.stringify(arguments));
});

and for iOS:


window.plugins.pushNotification.registerDevice({alert:true, badge:true, sound:true}, function(status) {
// if successful status is an object that looks like this:
// {"type":"7","pushBadge":"1","pushSound":"1","enabled":"1","deviceToken":"blablahblah","pushAlert":"1"}
});

As you can see, registering for push notifications requires different approaches for each platform.

4 No native UI support

There is no UI support in PhoneGap, so if there is a need to replicate a native widget we need to do that by using HTML/CSS/JS, the way we would when using Sencha Touch. A good example for this could be a date select widget that can be implemented as a popup.

5. Java, Objective-C or C# requirement to create new plugins

To extend PhoneGap through plugins one must know how to program in the native language of each platform. Of course, for a team that has developers available with knowledge of each technology this won’t be a problem, but for only one person or teams of web developers this is will be a real issue.

6. No built-in support for push notifications

Push notification is a very nice and frequently used feature and it should be built-in or at least implemented in some unified plugins.

Now, after we covered the key disadvantages of using the now popular framework PhoneGap, we can get to the up sides of using the less known but very promising alternative:

MoSync’s key features

1. Only one project structure for all the platforms

With MoSync you’ll have only one project to maintain for all the platforms. For iOS you will still need to use Xcode because MoSync outputs a project for it but, other than just building it, there is no need to dig deeper in Apple’s IDE.

2. The same JavaScript file

The entire provided functionality for JavaScript is placed in the same file for all of the operating systems. There are no files for plugins because it has none (at least that I know of), but the same extensibility is achieved in ways described in the next section.

3. No plugins, but…

If there is some functionality that MoSync doesn’t provide on the JavaScript side, there are no plugins that you can use, but there is another way. MoSync provides a lot of features from the C++ side and if they aren’t accessible from JavaScript by default they can be easily made available.

I’m sure that in the future the MoSync team will add more features to the JavaScript library.

4. Native UI support

With MoSync you are not restricted to only JavaScript frameworks to replicate native UI, you can truly create native UI elements that are more responsive using only JavaScript.

5. Extend JavaScript functionality using C++ or Java and Objective-C

If there is something that JavaScript can’t do or there is a need for more performance there is always the power of C++ to support you and the code written with it will work on every platform, no need to code in different languages for each.

If you need to code in a native environment to use some specific features of a platform you can always modify the MoSync runtimes (more info) and code your stuff in Java and Objective-C (just to name the two most popular at the moment). I think/hope MoSync developers will make this process easier in the future by allowing us to write extensions without modifying the runtime. I didn’t modify the runtime for iOS (yet) but I was able to build and modify it for Android to add a custom animation.

6. Built-in support for push notifications

MoSync provides built-in support for push notification with a unified interface on every supported platform.

Conclusion

Besides the native UI support, the feature I like the most in MoSync is the C++ support because it gives me more power over my application without the need to code the same functionality for every single platform.

As an example of how MoSync gives me more flexibility is how I can handle the application startup. When the app is launched a loading screen is displayed until the content is ready. The problem is that after the WebView is shown I need to add another loading indicator until all the needed files and data are loaded in it. With MoSync I was able to use C++ to display the WebView only after everything was loaded. To do that with PhoneGap I would need to do add the functionality in all the different platform projects.

If you know some C++ or you are willing to learn, MoSync is definitely worth checking out if you want to built cross-platform and hybrid apps.

What do you think?

If you liked this post
you can buy me a beer

One Response to Why MoSync could be a better alternative to PhoneGap

Add a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Also, if you want to display source code you can enclose it between [html] and [/html], [js] and [/js], [php] and [/php] etc