|By Michael E. Branstein and Nicholas J. Branstein
This article is excerpted from the first chapter of NativeScript in Action.
Many moons ago we were in the pre-iPhone era. For those of you reading this who remember, we were carrying around our Windows 6 mobile phones and geeking out over the latest Samsung Blackjack. There were fewer platforms and devices back then. Nowadays, new devices come out monthly. The increasingly frequent rate that devices are released has driven the development community to look for ways to write different types of mobile apps.
Different Types of Mobile Apps
In today’s world, mobile apps fall into one of four major categories: native; hybrid; cross-compiled; and just-in-time (JIT) compiled (table 1).
Table 1 Different mobile app types and their popular frameworks
|Mobile App Type||Framework|
DEFINITION: Just-in-time (JIT) compiled apps are apps that are compiled at runtime versus being compiled before the execution of the app. For example, in a just-in-time app, your source code isn’t compiled to native machine code until the absolute last minute, or immediately prior to executing each statement.
Excluding native apps, the other three app types in table 1 work towards the same goal of writing your app code once and deploying it to multiple platforms (which is what people mean when they say cross-platform). Although these devices try to achieve similar results, each mobile app type in table 1 reaches the goal utilizing a different route.
Figure 1 How different types of mobile apps run on a device
If you’re a .NET or Java developer, running code in a virtual machine will be familiar because both frameworks run their code in a virtualized manner. When the code in a JIT compiled app is run by a virtual machine on a device, you’ve access to all native hardware, features, and updates that the latest version of the device’s operating system may have released.
Why NativeScript is Important
Besides JIT compilation, NativeScript has many other differences from other mobile app frameworks. You’ll soon come to find out that these differences are what make NativeScript important in our minds.
NativeScript offers a truly write-once, deploy-everywhere framework. In my experience working with other frameworks, there’s a lot of “shim” code that needs to be written. This code acts like a piece of wood used to help frame a doorway. In most cases the doorway will fit perfectly, but sometimes we need to add a little here and a little there to get it to fit and work right. When writing code, you may need to add a bit of UI code to make a button display correctly in the Android version of the app. Likewise, you may need to write additional UI code to make the dropdown box look right in the iOS app.
Figure 2 NativeScript – write-once, deploy-everywhere
Figure 2 illustrates the example of the shim code. Other frameworks may require specific Android or iOS code be written for your app. NativeScript view code (and non-view code) is written one time and translates to a native experience on whatever platform you’re targeting and running your app on, which means you don’t need to write shim code. Even though you don’t have to write shim code in NativeScript apps, you can still write a fully-customized app using native features and hardware.
As we dig deeper into NativeScript, we’ll introduce you to the structured approach that NativeScript requires to create an app. This convention-based approach to creating apps also helps to set NativeScript apart from other frameworks.
What types of apps can be built with NativeScript?
If you’re feeling down because I shattered your Floppy Bunny idea, don’t worry, there are other types of apps that NativeScript is great for! Unlike our game example, NativeScript is a perfect choice if you’re developing a business to consumer app such as a news feed, a companion app for a website, a social media app, or even an app to control all the smart devices in your home!
How NativeScript Works
Figure 3 How NativeScript components and your app code work together to build and run native iOS and Android apps
Once you’ve developed your app code, the app core is fed into the NativeScript command line interface (CLI). The CLI is responsible for creating native Android and iOS projects and merging the NativeScript app core into them. The CLI invokes native software development kits (SDKs) to build and compile the native app projects (which include your app’s NativeScript core) into a native app. The compiled app is deployed by the CLI and run on a physical device, simulator, or emulator.
Try NativeScript for yourself!
Download the free first chapter of NativeScript in Action and see what NativeScript can do for you.
For more information (and a discount code) also see this Slideshare presentation.