Ionic end-to-end demonstration
Overview
The purpose of this demonstration is to explain an end-to-end flow. The following steps are carried out.
- A sample application that is pre-bundled with the PMF client SDK is registered and downloaded from the PMF Operations Console.
- A new or provided adapter is deployed to the PMF Operations Console.
- The application logic is changed to make a resource request.
End result:
- Successfully ping the PMF.
- Successfully retrieve data using an adapter.
Prerequisites:
- Xcode for iOS, Android Studio for Android or Visual Studio 2015 or greater for Windows 10 UWP
- Ionic CLI
- Optional. PMF CLI (download).
- Optional. Stand-alone PMF (download).
Step 1. Starting the PMF
Make sure you have created a Persistent Mobile Foundation instance, or if you are using the PMF Developer Kit, navigate to the server’s folder and run the command: ./run.sh
in Mac and Linux or run.cmd
in Windows.
Step 2. Creating and registering an application
Open the PMF Operations Console by loading the URL: http://your-server-host:server-port/mfpconsole
in a browser. If server is running locally, use http://localhost:9080/mfpconsole
. The username/password is admin/admin.
- Click the New button next to Applications
- Select a platform from the list of platforms: Android, iOS, Windows, Browser
- Enter com.sample.ionic as the application identifier
- Enter 1.0.0 as the version
- Click on Register application
- Download the sample Ionic application from Github.
Step 3: Adding the Mobile Foundation SDK to Ionic application
Follow the steps below to add Mobile Foundation Ionic SDK to the downloaded Ionic sample application.
-
Navigate to the root of your existing Ionic project and add the PMF core Ionic Cordova plug-in.
-
Change directory to the root of the Ionic project:
cd MFPStarterIonic
-
Add the PMF Plugins by using the Ionic CLI command:
ionic cordova plugin add cordova-plugin-name
For example:ionic cordova plugin add cordova-plugin-mfp
The above command adds Mobile Foundation Core SDK Plugin to the Ionic project.
-
Add one or more supported platforms to the Cordova project by using the Ionic CLI command:
ionic cordova platform add ios|android|windows|browser
. For example:cordova platform add ios
-
Prepare the application resources by running the
ionic cordova prepare command
:ionic cordova prepare
Step 4. Editing application logic
-
Open the Ionic project in the code editor of your choice.
-
Select the src/js/index.js file and paste the following code snippet, replacing the existing
WLAuthorizationManager.obtainAccessToken()
function:
WLAuthorizationManager.obtainAccessToken("").then(
(token) => {
console.log('--> pingMFP(): Success ', token);
this.zone.run(() => {
this.title = "Yay!";
this.status = "Connected to Mobile Foundation Server";
});
var resourceRequest = new WLResourceRequest( "/adapters/javaAdapter/resource/greet/",
WLResourceRequest.GET
);
resourceRequest.setQueryParameter("name", "world");
resourceRequest.send().then(
(response) => {
// Will display "Hello world" in an alert dialog.
alert("Success: " + response.responseText);
},
(error) => {
alert("Failure: " + JSON.stringify(error));
}
);
}, (error) => {
console.log('--> pingMFP(): failure ', error.responseText);
this.zone.run(() => {
this.title = "Bummer...";
this.status = "Failed to connect to Mobile Foundation Server";
});
}
);
Step 5. Deploy an adapter
Download this adapter artifact and deploy it from the PMF Operations Console using the Actions → Deploy adapter action.
Alternatively, click the New button next to Adapters.
-
Select the Actions → Download sample option. Download the Hello World Java adapter sample.
If Maven and PMF CLI are not installed, follow the on-screen Set up your development environment instructions.
-
From a Command-line window, navigate to the adapter’s Maven project root folder and run the command:
pmfdev adapter build
-
When the build finishes, deploy it from the PMF Operations Console using the Actions → Deploy adapter action. The adapter can be found in the [adapter]/target folder.
Step 6. Testing the application
- From a Command-line window, navigate to the Cordova project’s root folder.
- Run the command:
ionic cordova platform add ios|android|windows|browser
to add a platform. - In the Ionic project, select the config.xml file and edit the
<mfp:server ... url=" "/>
value with the protocol, host and port properties with the correct values for your PMF.- If using a local PMF, the values are typically http, localhost and 9080.
- If using a remote PMF (on IBM Cloud), the values are typically https, your-server-address and 443.
- If using a Kubernetes cluster on IBM Cloud Private and if the deployment is of type NodePort, the value of the port would typically be the NodePort exposed by the service in Kubernetes cluster.
Alternatively, if you have installed the PMF CLI, then navigate to the project root folder and run the command
pmfdev app register
. If a remote PMF is used, run the commandpmfdev server add
to add the server, followed by the command to register the app, for example:
pmfdev app register myIBMCloudServer
If a device is connected, the application is installed and launched in the device. Otherwise, the simulator or emulator will be used.
Results
- Clicking the Ping PMF button displays Connected to PMF.
- If the application was able to connect to the PMF, a resource request call using the deployed Java adapter takes place. The adapter response is then displayed in an alert.
Next steps
Learn more on using adapters in applications, and how to integrate additional services such as Push Notifications, using the PMF security framework and more:
- Review the Application development tutorials
- Review the Adapters development tutorials
- Review the Authentication and security tutorials
- Review the Notifications tutorials
- Review All Tutorials