Base de connaissance Apps Panel

S’abonner

Intégration du SDK

  Mise en place du SDK :

1. Dans votre projet Visual Studio, faites un clic droit sur Références>Gérer mes packages NuGet

2. Dans la fenêtre de recherche taper : « Plugin.SDKAppsPanel »

3. Visual Studio vous proposera le package correspondant, installez la dernière version.

4. Au moment de l’installation, Visual Studio vous demandera d’accepter des licences de librairies Microsoft, cliqué sur le bouton d’acceptation.

5. Cette installation ajoutera un ensemble de librairies requis pour l’utilisation du MBAaS Apps Panel.

6. Veuillez vérifier la présence des Capacités suivante :

  • Si projet Windows Phone Silverlight :

    • Dans le WMAppManifes.xml :
      • ID_CAP_IDENTITY_DEVICE
      • ID_CAP_LOCATION
      • ID_CAP_NETWORKING
      • ID_CAP_PUSH_NOTIFICATION

       

    • Dans le Package.appxmanifest :
      • Location
      • Internet (client&serveur)
    • Si projet Windows Phone Runtime

      • Dans le Package.appxmanifest :
        • Location
        • Internet (client&serveur)
      • Si projet Windows Runtime :

        • Dans le Package.appxmanifest :
          • Location
          • Internet (client&serveur)
          • Interner (client)

7. Si votre projet est un projet Windows Phone Sylverlight, veuillez modifier le système de notification par WNS dans le WMAppManifest.xml .

8. Au niveau du fichier app.xaml.cs veuillez ajouter les implémentations suivantes :

                     1) Sur Windows Phone silverlight :

// Code to execute when the application is activated (brought to foreground)

// This code will not execute when the application is first launched

private async void Application_Activated(object sender, ActivatedEventArgs e)
{
    if (PhoneApplicationService.Current.State.ContainsKey("StartApp"))
    {
               List a = PhoneApplicationService.Current.State["RegisteredAction"] as List;
               List b = PhoneApplicationService.Current.State["RegisteredView"] as List;
               DateTime c = Convert.ToDateTime(PhoneApplicationService.Current.State["StartApp"].ToString());
               DateTime d = Convert.ToDateTime(PhoneApplicationService.Current.State["CloseApp"].ToString());
               await APStats.sendValueSylverlight(c, d, a, b);
    }
}

 
// Code to execute when the application is deactivated (sent to background)

// This code will not execute when the application is closing

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    PhoneApplicationService.Current.State["RegisteredAction"] = APStats.registeredAction;
    PhoneApplicationService.Current.State["RegisteredView"] = APStats.registeredViewInAppsPanelForAction;
    PhoneApplicationService.Current.State["StartApp"] = AppsPanel.Instance.StartApp;
    PhoneApplicationService.Current.State["CloseApp"] = DateTime.Now;
}
 

// Code to execute on Unhandled Exceptions

private async void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
    Dictionary<string, string> crashInfo = new Dictionary<string, string>();
    e.Handled = true;
    crashInfo.Add("content", e.ExceptionObject.StackTrace);
    crashInfo.Add("name", e.ExceptionObject.GetType().Name);
    crashInfo.Add("reason", e.ExceptionObject.Message);
    await CrashReportTool.CrashReport(crashInfo);
    App.Current.Terminate();
    if (Debugger.IsAttached)
    {
               // An unhandled exception has occurred; break into the debugger
               Debugger.Break();
    }
}

 

                       2) Sur Windows Phone Runtime et Windows Runtime :


/// 
/// Initializes the singleton application object.  This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// 
public App()
{
    this.InitializeComponent();
    this.Suspending += this.OnSuspending;
    this.UnhandledException += App_UnhandledException;
}
private async void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    Dictionary<string, string> crashInfo = new Dictionary<string, string>();
    e.Handled = true;
    crashInfo.Add("content", e.Exception.StackTrace);
    crashInfo.Add("name", e.Exception.GetType().Name);
    crashInfo.Add("reason", e.Exception.Message);
    await CrashReportTool.CrashReport(crashInfo);
    App.Current.Exit();
}
/// 
/// Invoked when application execution is being suspended.  Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// 
///The source of the suspend request.
///Details about the suspend request.

private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
    await APStats.sendValue();
    deferral.Complete();
}
/// 
/// Invoked when the application is launched normally by the end user.  Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// 
///Details about the launch request and process.

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
    if (System.Diagnostics.Debugger.IsAttached)
    {
               this.DebugSettings.EnableFrameRateCounter = true;
    }

#endif
    if (!String.IsNullOrWhiteSpace(e.Arguments))
    {
               string namePlusBase64 = e.Arguments;
               string DataPlusBase64 = namePlusBase64.Split('?')[1];
               string base64 = DataPlusBase64.Substring(5);
               byte[] data = Convert.FromBase64String(base64);
               string decodedString = Encoding.UTF8.GetString(data, 0, data.Length);
               JToken toastJson = JObject.Parse(decodedString);
               if (toastJson["url"] != null)
               {
                              this.UrlPush = toastJson["url"].ToString();
                              MessageDialog UrlPopUp = new MessageDialog(toastJson["aps"]["alert"].ToString());
                              UrlPopUp.Commands.Add(new UICommand("OK", new UICommandInvokedHandler(this.OkPopupUrl)));
                              UrlPopUp.Commands.Add(new UICommand("Ouvrir", new UICommandInvokedHandler(this.OpenPopupUrl)));
                              UrlPopUp.ShowAsync();
               }
               else
               {
                              MessageDialog classicPopUp = new MessageDialog(toastJson["aps"]["alert"].ToString());
                              classicPopUp.ShowAsync();
               }
    }
    Frame rootFrame = Window.Current.Content as Frame;
    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == null)
    {
               // Create a Frame to act as the navigation context and navigate to the first page
               rootFrame = new Frame();

               // TODO: change this value to a cache size that is appropriate for your application
               rootFrame.CacheSize = 1;

               // Set the default language
               rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
               if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
               {
                              // TODO: Load state from previously suspended application
               }
               // Place the frame in the current Window
               Window.Current.Content = rootFrame;
    }
    if (rootFrame.Content == null)
    {
               // Removes the turnstile navigation for startup.
               if (rootFrame.ContentTransitions != null)
               {
                              this.transitions = new TransitionCollection();
                              foreach (var c in rootFrame.ContentTransitions)
                              {
                                             this.transitions.Add(c);
                              }
               }
               rootFrame.ContentTransitions = null;
               rootFrame.Navigated += this.RootFrame_FirstNavigated;

               // When the navigation stack isn't restored navigate to the first page,
               // configuring the new page by passing required information as a navigation
               // parameter
               if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
               {
                              throw new Exception("Failed to create initial page");
               }
    }
    // Ensure the current window is active
    Window.Current.Activate();
}

private void OpenPopupUrl(IUICommand command)
{
    Uri theLink = new Uri(this.UrlPush);
    Windows.System.Launcher.LaunchUriAsync(theLink);
}
 

private void OkPopupUrl(IUICommand command)
{

}

Si votre projet est un projet Windows Phone Silverlight, au niveau du fichier MainPage.xaml.cs, veuillez ajouter l’implémentation suivante :


protected override void OnNavigatedTo(NavigationEventArgs e)
{
   base.OnNavigatedTo(e);
   if (this.NavigationContext.QueryString.ContainsKey("data"))
   {
         string jsonEncode = this.NavigationContext.QueryString["data"];
         byte[] data = Convert.FromBase64String(jsonEncode);
         string decodedString = Encoding.UTF8.GetString(data, 0, data.Length);
         JToken toastJson = JObject.Parse(decodedString);
         if (toastJson["url"] != null)
         {
        MessageBoxResult popupResult = MessageBox.Show(toastJson["aps"["alert"].ToString(), "", MessageBoxButton.OKCancel);
                 if(popupResult == MessageBoxResult.OK)
                 {
                           Launcher.LaunchUriAsync(new Uri(toastJson["url"].ToString()));
                  }
         }
         else
         {
           MessageBox.Show(toastJson["aps"]["alert"].ToString());
         }
   }
}

10. Pour initialiser le SDK vous n’avez qu’a ajouter la ligne suivante dans le constructeur de la première page appelé par votre application :

AppsPanel.Instance.Init("fr", "cleAppsPanel", "VersionDeLapp", "CodeAppsPanel", this);

NB : Pour un fonctionnement optimal veuillez ajouter using Plugin.SDKAppsPanel; dans toutes les pages où vous utilisez des implémentations du SDK Apps Panel.

Cet article vous a-t-il été utile ?
Utilisateurs qui ont trouvé cela utile : 0 sur 0
Vous avez d’autres questions ? Envoyer une demande