Adding the Persistent Mobile Foundation SDK to Xamarin Applications

Overview

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.

Creating 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 & PersistentMobileFoundationPush) from this path: To add the Xamarin SDK, first 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 Persistent Mobile Foundation. You can add required xcframeworks via Native References. You can download iOS SDK/xcframeworks from this path: PMF Operations Console → Download Center → SDKs tab Add Xamarin

Process to configure new package source.

  1. Right click on Packages folder of Xamarin Project and select Manage NuGet Packages option from dropdown. Adding sdk from nuget.org
  2. Select Configure Resources from next small popup window. Configure Resources
  3. Provide input to add new Package Resource within new popup box.
    • Name : Package Resource Name
    • Location : Path to the folder where you have kept Persistent Mobile Foundation Nuget files.
    • Username : Optional
    • Password : Optional Add new Package Resource
  4. New Package Resources will be listed as below.
    Successfull addition
  5. Now, select your new Package Resources from dropdown like below Resource dropdown

Above image showing PMF_Nuget pointing a custom local path to Nuget files.

Registering the application

  1. Load the PMF Operations Console.
  2. Click the New button next to Applications to register a new application and follow the on-screen instructions.
  3. 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 and Info.plist respectively.
  4. After the application is registered, navigate to the application’s Configuration Files tab and copy or download the mfpclient.plist and mfpclient.properties file. Follow the onscreen instructions to add the file to your project.

Completing the setup process

mfpclient.plist

  1. Right-click the Xamarin iOS project and select Add files... Browse and find the mfpclient.plist to the root of the project. Choose Copy file to project if prompted.
  2. Right-click the mfpclient.plist file and select Build action.Choose Content.

mfpclient.properties

  1. Right-click the Assets folder of Xamarin Android project and select Add files... Browse and find the mfpclient.properties to the folder. Choose Copy file to project if prompted.
  2. 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.168.1.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:

Last modified on