Install

Add NuGets packages

You can find NuGets packages here : https://www.nuget.org/packages?q=XAPM

In main project, add NuGet package :

  • XAPM.Interface

In iOS project, add NuGet packages :

  • XAPM.Interface

  • XAPM.iOS.Impl

  • XAPM.iOS.SDK

In Android project, add NuGet packages :

  • XAPM.Interface

  • XAPM.Droid.Impl

  • XAPM.Droid.SDK

Init SDK

In main project, in file App.xaml.cs, init the SDK :

  • partnerID : <PARTNER_ID>

  • partnerSecret : <PARTNER_SECRET>

  • appId : <APP_ID>

  • baseUrl : <BASE_URL>

public App()
{
    InitializeComponent();
    
    APM.Register();
    APM.SetBaseUrl(<BASE_URL>);
    APM.InitApp(<PARTNER_ID>, <PARTNER_SECRET>, <APP_ID>);
    
    MainPage = new MainPage();
}

In file MainPage.xaml.cs, call the method APM.RefreshSDK();

public MainPage()
{
    InitializeComponent();
    
    APM.RefreshSDK();
}

In iOS project, in file AppDelegate.cs, init iOS SDK :

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());
    
    XAPM.iOS.Impl.Initializer.Init();
    
    return base.FinishedLaunching(app, options);
}

In Android project, in file MainApplication.cs, init Android SDK :

public override void OnCreate()
{
    base.OnCreate();
    RegisterActivityLifecycleCallbacks(this);
    // A great place to initialize Xamarin.Insights and Dependency Services!
    XAPM.Droid.Impl.Initializer.Init();
}

Now, you can launch the app and verify that the badge appears.

Connection client

Use the method APMUIServicesUser UserClientConnect() for connect automatically your user to app’s miles.

If no account exist with this informations, the server create automatically this account.

This method needs : « email », « userID » and « optIn »

  • « email » is the email of user

  • « userID » is a unique identifier in your database

  • « optIn » is the RGPD OptIn

If you don’t want pass the email, you can build a encrypted email with the userID, for example : 123456789@appsmiles.f (123456789 is the userID)

string userID = "demo-test";
string email = partnerClientId + "@demo.com";
int optIn = APMServicesConfig.APM_DEVICE_OPT_IN_ACCEPT();
APMUIServicesUser.UserClientConnect(email, userID, optIn, delegate (Dictionary<string, Object> user) {
    Debug.WriteLine("user.email : " + user["email"]);
}, delegate (Dictionary<string, Object> error) {
    Debug.WriteLine("error.errorCode : " + error["errorCode"]);
    Debug.WriteLine("error.errorMsg : " + error["errorMsg"]);
});

Show/Hide badge

If you want to hide the badge on some screens

APM.HideBadge();

Don’t forget to re-show badge after hiding

APM.ShowBadge();

Tagging plan

Call triggerAction for send a tag

APM.TriggerAction("challenge1"); //challenge1 → actionName

Onboarding process

Implements this for :

– app’s miles account and client account not connected, so, redirect user to your process login/register account

– app’s miles account not connected and client account connected, so, connect app’s miles account with method userClientConnect

– app’s miles account and client account connected, so, nothing

public partial class MainPage : ContentPage
{
    //Declare a object of APMOnboardingUtils in your class
    private APMOnboardingUtils mOnboardingUtils;
    
    public MainPage()
    {
        InitializeComponent();
        APM.RefreshSDK();
        mOnboardingUtils = new APMOnboardingUtils(delegate () {
        
            Debug.WriteLine("APMOnboardingUtils.OK");
            
            //Get the event OnboardingButtonOkClicked
            bool clientAccountConnected = true;
            if (clientAccountConnected) //TODO: check if account client is connected
            {
                //Account client is connected
                Dictionary<string, object> user = APM.GetUser();
                if (user != null && user["userToken"] != null && !user["userToken"].Equals(""))
                {
                    //Client account connected and app's miles account connected
                    Debug.WriteLine("Client account connected and app's miles account connected");
                }
                else
                {
                    //Client account connected --> need to connect app's miles account
                    Debug.WriteLine("Client account connected --> need to connect app's miles account");
                    //ApmConnection();
                }
            }
            else
            {
                //TODO show screen login/create account
            }
        
        
        }, delegate () {
        
            Debug.WriteLine("APMOnboardingUtils.Later");
        
        }, delegate () {
        
            Debug.WriteLine("APMOnboardingUtils.Never");
        });
        
        //Listen events of onboarding
        mOnboardingUtils.RegisterNotifications();
    }
}

Call unregister when the screen is in pause:

//Unlisten events of onboarding
mOnboardingUtils.unregister(this);

You can also see the native documentation here:

pageAndroidpageiOS

Last updated