Adding the Persistent Mobile Foundation SDK to Xamarin Applications
Release 9.0.3
The PMF SDK consists of a collection of dependencies that are packaged inside a NuGet package that can be added to your Visual Studio project from Nuget Package Manager.
The packages correspond to core functions and other functions:
-
PersistentMobileFoundation - Contains MobileFirst client sdk libraries which implements client-to-server connectivity, handles authentication and security aspects, resource requests, and other required core functions along with JSONStore framework.
-
PersistentMobileFoundationPush - Contains the push notification framework. For more information, review the Notifications tutorials.
In this tutorial you learn how to add the PMF Native SDK by using NuGet Package Manager to a new or existing Xamarin.Android or Xamarin.iOS application. You also learn how to configure the PMF to recognize the application.
Prerequisites
- Visual Studio 2017 installed on the developer workstation for macOS.
- Visual Studio 2015 or Visual Studio 2017 community Version installed on the developer workstation for Windows OS. Make sure that you are not using Express edition of Visual Studio.If so it is recommended to update to a Community edition.
- A local or remote instance of PMF Server is running.
- Read the Setting up your PMF development environment and Setting up your Xamarin development environment tutorials.
Jump to:
Add Xamarin SDK to application
Follow the instructions below to add the PMF Native SDK to a new or existing Visual Studio project, and to register the application to the PMF.
Before you start, make sure that the PMF Server is running.
If using a locally installed server: From a Command-line window, navigate to the server’s folder and run the command: ./run.sh
.
- Create an application. Create a Xamarin solution using Xamarin Studio or Visual Studio or use an existing one.
-
Download Xamarin SDKs. You can download Xamarin SDKs (PersistentMobileFoundation and PersistentMobileFoundationPush) from this path:
Download the
SDK.zip
file from the PMF Operations Console → Download Center → SDKs tab. -
Add Xamarin SDKs to application.
After you have downloaded Xamarin SDKs from the location, keep those SDKs in a convenient folder location to add them via the package source. You need use Xamarin SDKs in Xamarin (iOS project) along with xcframeworks of the Persistent Mobile Foundation. You can add required xcframeworks through Native References.
You can download iOS SDK/xcframeworks from this path:
PMF Operations Console → Download Center → SDKs tab
Configuring new package source
-
Right click on Packages folder of Xamarin Project and select Manage NuGet Packages option.
-
Select Configure Resources from the popup window.
- Provide the following inputs to add new package resource.
- Name : Package Resource Name
- Location : Path to the folder where you have kept the Persistent Mobile Foundation Nuget files.
- Username : Optional
- Password : Optional
-
New package resources will be listed as shown below.
- Now, select your new package resources from dropdown as shown below.
Above image showing PMF_Nuget pointing a custom local path to Nuget files.
Registering the application
- Load the PMF Operations Console.
-
Click New next to Applications to register a new application and follow the on-screen instructions.
Android and iOS applications have to be registered separately. This ensures both the Android application and iOS application can connect successfully to the server.
The registration details for Android and iOS applications can be found in the
AndroidManifest.xml
andInfo.plist
respectively. - After the application is registered, navigate to the application’s Configuration Files tab and copy or download the
mfpclient.plist
andmfpclient.properties
file. Follow the onscreen instructions to add the file to your project.
Completing the setup process
mfpclient.plist
- Right-click the Xamarin iOS project and select Add files. Browse and find the
mfpclient.plist
to the root of the project. If prompted, choose Copy file to project. - Right-click the
mfpclient.plist
file and select Build action. Choose Content.
mfpclient.properties
- Right-click the Assets folder of Xamarin Android project and select Add files. Browse and find the
mfpclient.properties
to the folder. If prompted, choose Copy file to project. - Right-click the
mfpclient.properties
file and select Build action. Choose Android asset.
Referencing the SDK
Whenever you want to use the PMF Native SDK, make sure that you import the PMF framework: ** CommonProject**
using Worklight;
iOS
using MobileFirst.Xamarin.iOS;
Android
using Worklight.Xamarin.Android;
Updating the PMF Native SDK
To update the Persistent Mobile Foundation Native SDK with the latest release, remove the older nuget and add a new nuget.
Generated PMF Native SDK artifacts
mfpclient.plist
This file defines the client-side properties used for registering your iOS app on the PMF.
Property | Description | Example values |
---|---|---|
protocol | The communication protocol with the PMF. | http or https |
host | The host name of the PMF. | 192.0.2.63 |
port | The port of the PMF. | 9080 |
wlServerContext | The context root path of the application on the PMF. | /mfp/ |
languagePreferences | Sets the default language for client sdk system messages. | en |
Tutorials to follow next
With the PMF Native SDK now integrated, you can now:
- Review the Adapters development tutorials
- Review the Authentication and security tutorials
- Review the Notifications tutorials
- Review All Tutorials