For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.
Create a new Cordova app with the MobileFirst template
We can use a template to easily create a simple Cordova app that is enabled for IBM MobileFirstâ„¢ Platform Foundation. We can use this app as a starting point to build your own.
Before you begin
- You must have Cordova development tools installed. This example uses the Apache Cordova CLI. If we use other Cordova development tools, some of your steps will be different. Refer to our Cordova tool documentation for instructions.
- You must have the IBM MobileFirst Platform Command Line Interface (CLI) installed. For more information, see Install the MobileFirst Platform CLI.
- You must have internet access.
- You must have node.js version 4.0.0 or later installed.
The template creates a simple mobile app that displays the text Hello World. To create your Cordova application with the template, you add the template when you initially create your Cordova app with your Cordova development tools.
The template automatically adds the following plug-ins to our app: cordova-plugin-mfp, cordova-plugin-whitelist and cordova-plugin-splashscreen. The cordova-plugin-mfp plug-in is required for a MobileFirst Cordova app. Most applications will need the cordova-plugin-whitelist and cordova-plugin-splashscreen plug-ins. If your app will not need these, we can remove them after the app is initially created. The following steps show how to create your app with the template by using the Apache Cordova CLI:
Procedure
Enter the following command in your command window, where AppName is the name of the new app:
cordova create AppName --template cordova-template-mfp
Results
In the www directory of your of your app, (AppName/www), the index.html file contains a simple app that displays Hello World.
What to do next
Add platforms, additional MobileFirst plug-ins, and optionally, other plug-ins to our app. For more information, see Create a new Cordova app without the MobileFirst template. If your app does not need the cordova-plugin-whitelist or cordova-plugin-splashscreen plug-ins, we can remove them.
To further develop your app with features that depend on the MobileFirst Server, register your app with the server. For more information, see Register Cordova applications from the MobileFirst Platform CLI.
Important: (Android and iOS development only.) If you are developing your app for the Android or iOS platforms, when you add the platform to our app that contains the cordova-plugin-mfp plug-in, an existing file in your app is replaced by a version of the file that is provided by MobileFirst Platform Foundation. These files are:
- Android: The file MainActivity.java is replaced. Your original MainActivity.java file is backed up and renamed MainActivity.original.
- iOS: File main.m is replaced. Your original main.m file is backed up and renamed main.m.bak.
If you made any changes to the original versions of these files, we must merge the changes that you made into the new version of the file that is provided by IBM MobileFirst Platform Foundation.
Parent topic: Create Cordova apps that include MobileFirst features