Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Cross Platform Mobile Architecture
There is an explosion of smart mobile phones in market. And the need has become to support all the popular platforms like iOS, Android, WP8, Blackberry, etc. To write a platform specific application causes increase in efforts, resources and the cost factor. Cross Platform architecture is the solution to make this difficult task easy and it can be developed using Web or Hybrid app development methods.
In this article we will look at various architectures for mobile development and those supporting cross platform development. Also we will look at some of the third party frameworks which took the cross platform capabilities to a step further. It also provided out of the box solution for multi-platform support with nil or minimal code changes.
Mobile Application Development
To understand Cross Platform Mobile Architecture we first will need to understand the types of mobile app development strategies.
- Native Apps
Apps developed that are Mobile platform specific. They are developed using the native code sdks and will be very specific coding related to that platform.
- Web Apps
- Hybrid Apps
In this app, majority of the app is developed using web standards and is wrapped in a native shell/wrapper. These wrappers give access to mobile platform specific features like GPS or camera, native app UI look and feel, etc.
The diagram below shows a comparison of various app development strategies and indicates the cross platform capability which is least on left and most at the right.
Cross Platform Mobile Architecture & Hybrid/Web Apps
Hybrid Apps takes advantage of both native and web app development and is the best choice for creating cross platform applications. Following are the advantages of using a hybrid technique of app development:
- Cross platform & Code Sharing – Code once and use it to deploy to various mobile platforms. Use the same HTML UI interface code/third party library code for multiple devices.
- Native calls using the Native shell.
- Offline mode helps in giving access to application even if internet is not available.
- Due to cross platform a large number of users can be provided with the application.
- Mobile device can be leveraged for local processing, which is not possible for Web apps.
- App Store distribution gives a native update feel for user.
- Notifications regarding application and the updates can be provided.
Web Apps allows cross platform capability but is limited. Developers will not be able to take advantage of native UI, local processing and wont be good choice for performance critical apps. But if performance is not an issue and hosting a web app suffices your requirement then this will give you perfect cross compatibility without any overhead of using third party frameworks and can leverage the existing expertise in web technologies.
Native Apps provide very limited to no cross platform advantage, and hence are not recommended for cross platform architecture. But with WP8 there is some scope for code sharing. Use Xamarin to reuse the C# code for other platform app development. Also you can share the same code for Windows 8 platform using techniques like Portable Class Library, Windows Runtime API, etc. Further reference: Maximize code reuse between Windows Phone 8 and Windows 8
Cross Platform Architecture & Code Sharing
You can implement a Cross Platform Architecture using following methods:
Hybrid Local App
Hybrid Server App
You can create a mobile web application and hoist it to a server and simply call the web url in the native shell/container. In this approach your processing will all be done at server. You can improvise the performance by local caching but still not a right choice for performance critical apps. Deploying changes will be easy as you need to change the code and put it in server.
To create a Hybrid WP8 app using this approach:
- Visual Studio 2012 -> New Project -> Windows Phone Application (Silverlight). This will create a native WP app shell.
- Add a WebBrowser control to the application page and direct it to the web app hosted on server.
That is it and now your cross platform app is instantly ready.
Third Party Frameworks
Apache Cordova PhoneGap, Sencha Touch & Xamarin.Mobile are example of cross platform tools that provide the wrappers over the native APIs. Because of this its help in cross platform compatibility. You write the code in one language and compile it to the required targets say WP, iPhone, android or other supported devices.
Code Sharing is taken to a next level using this frameworks. In a typical Hybrid application the only reusable code & cross platform capability is limited to the web technologies used. But now the native functionality can be utilized using these frameworks and thus making the Hybrid Apps truly cross platform and much more reusable.
For more information refer Cordova (PhoneGap) and Windows Phone 8
An example of how to get started with WP8 and PhoneGap can be found here Camera Pic & GeoTagging App using PhoneGap
It provides rich HTML5 framework and native api wrappers. Code once and compile to different mobile platforms thus making your application cross platform.
For more information refer Sencha Touch and Windows Phone 8
It lets you use your existing WP8 or Windows 8 middle tier app logic which is in C# and can share this code on various other mobile platforms. Xamarin compiler bundles the .NET runtime and outputs a native executable, packaged as an iOS or Android app. Xamarin extends the code sharing not only for various mobile platforms but also with Windows 8 code.
For more information refer Xamarin Mobile and Windows Phone 8
The following documentation will provide an in depth understanding of how to create cross platform application using Xamarin: http://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications
It is a Touch-Optimized HTML5 Web UI Framework based on progressive enhancement and responsive web design (RWD) principles. You can create cross platform code using this framework.
For more information refer JQuery Mobile and Windows Phone
We have seen what are the advantages of Cross Platform Architecture and how it can implemented using various development strategies. No one methodology can be best, the one that suits best you requirement must be utilized.
Cross Platform Architecture is highly recommended for Enterprise applications as that will help to reduce the time to market and capture the opportunity by using the existing code and target all clients with different mobile platform.