Exemple #1
0
        private static void NotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
        {
            try
            {
                String notificationContent = String.Empty;

                switch (args.NotificationType)
                {
                case PushNotificationType.Badge:
                    notificationContent = args.BadgeNotification.Content.GetXml();
                    break;

                case PushNotificationType.Tile:
                    notificationContent = args.TileNotification.Content.GetXml();
                    break;

                case PushNotificationType.Toast:
                    notificationContent = args.ToastNotification.Content.GetXml();
                    break;

                case PushNotificationType.Raw:
                    notificationContent = args.RawNotification.Content;
                    break;
                }

                ToastMessage message = JsonConvert.DeserializeObject <ToastMessage>(notificationContent);
                if (App.ApplicationApplicationState == Enums.ApplicationStateType.Active)
                {
                    args.Cancel = true;
                    try
                    {
                        if (ChatPageViewModel.SelectedFriend.Id != message.FromId)
                        {
                            ToastHelper.DisplayTextToast(ToastTemplateType.ToastImageAndText01, message.FromId, message.Content, message.FromPicture);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
                else
                {
                }
                ChatPageViewModel chatPageViewModel = ServiceLocator.Current.GetInstance <ChatPageViewModel>();
                chatPageViewModel.UpdateMessages(message.FromId, message.Content);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Exemple #2
0
        private void RegistrationCompleted(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
            ApplicationDataContainer container = ApplicationData.Current.LocalSettings;

            try
            {
                var content = container.Values["RawMessage"].ToString();
                if (content != null)
                {
                    ToastMessage message = JsonConvert.DeserializeObject <ToastMessage>(content);
                    ToastHelper.DisplayTextToast(ToastTemplateType.ToastImageAndText01, message.FromId, message.Content, message.FromPicture);
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }