Exemplo n.º 1
0
        protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            base.OnBackgroundActivated(args);
            deferral = args.TaskInstance.GetDeferral();
            args.TaskInstance.Canceled += (s, r) =>
            {
                Debug.WriteLine($"Task canceled for {r}");
                deferral.Complete();
            };

            Debug.WriteLine($"{args.TaskInstance.Task.Name} activated in background with {args.TaskInstance.TriggerDetails.GetType().ToString()}");

            if (args.TaskInstance.TriggerDetails is RawNotification)
            {
                var rawNotification = args.TaskInstance.TriggerDetails as RawNotification;
                Debug.WriteLine($"RawNotification received {rawNotification.Content}");

                if (NotificationsManager == null)
                {
                    NotificationsManager = new GraphNotificationsManager();
                }

                await NotificationsManager.HandlePushNotificationAsync(rawNotification.Content);
            }

            deferral.Complete();
            Debug.WriteLine($"Task completed");
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage                = MainPage.Current;
            notificationsManager    = ((App)Application.Current).NotificationsManager;
            RefreshButton.IsEnabled = (notificationsManager != null);
            if (notificationsManager != null)
            {
                Description.Text = "Welcome " + notificationsManager.SignedInAccount?.Username;
                if (notificationsManager.UserNotificationSubscriptionId != null)
                {
                    TextBox_SubscriptionId.Text = notificationsManager.UserNotificationSubscriptionId;
                }

                notificationsManager.CacheUpdated += Cache_CacheUpdated;
            }
            notificationsManager?.SubscribeAsync();
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     rootPage             = MainPage.Current;
     notificationsManager = ((App)Application.Current).NotificationsManager;
     UpdateView(GetCurrentLoginState());
 }