コード例 #1
0
        public static async Task SetupNotificationsIfNeeded(INotificationsService notificationsService, IUniversalWindowsRemoteNotificationsPresenter notificationsPresenter)
        {
            _notificationsPresenter = notificationsPresenter;
            if (PushNotificationChannel == null)
            {
                PushNotificationChannel = await PushNotificationChannelManager
                                          .CreatePushNotificationChannelForApplicationAsync();

                PushNotificationChannel.PushNotificationReceived += PushChannel_PushNotificationReceived;
            }

            await Task.Run(async() =>
            {
                bool?booleanValue = false;
                lock (synchronizationObject)
                {
                    booleanValue = ApplicationData.Current.LocalSettings.Values[ShouldForceSubcribeToPushSettingsKey] as bool?;
                }

                if (booleanValue.HasValue && booleanValue.Value)
                {
                    await Polly.Policy
                    .Handle <Exception>()
                    .WaitAndRetryForever(x => TimeSpan.FromMinutes(5))
                    .ExecuteAsync(async() =>
                    {
                        await notificationsService.SubscribeToNotifications(true);
                        lock (synchronizationObject)
                        {
                            ApplicationData.Current.LocalSettings.Values[ShouldForceSubcribeToPushSettingsKey] = false;
                        }
                    });
                }
            });
        }
コード例 #2
0
        public static void HandlePushActivation(IActivatedEventArgs e, IUniversalWindowsRemoteNotificationsPresenter presenter)
        {
            var toastNotificationActivatedEventArgs = e as ToastNotificationActivatedEventArgs;

            if (toastNotificationActivatedEventArgs == null)
            {
                return;
            }

            presenter.HandleRemoteNotificationActivation(toastNotificationActivatedEventArgs.Argument ?? string.Empty);
        }
コード例 #3
0
 public UWPRemotePushNotificationsService(IPersistedStorage persistedStorage, IRemotePushRegistrationService remotePushRegistrationService, IPushTagsProvider pushTagsProvider, IUniversalWindowsRemoteNotificationsPresenter remoteNotificationsPresenter)
 {
     uwpNotificationsService =
         new PushInvalidateRegistrationAppUpdateBackgroundTaskNotificationsServiceDecorator(
             new PushBackgroundTaskNotificationServiceDecorator(
                 new UniversalWindowsRemotePushNotificationService(persistedStorage,
                                                                   remotePushRegistrationService, pushTagsProvider)
                 ));
 }
コード例 #4
0
 public UWPRemotePushNotificationsService(IRemotePushRegistrationService remotePushRegistrationService, IPushTagsProvider pushTagsProvider, IUniversalWindowsRemoteNotificationsPresenter remoteNotificationsPresenter)
     : this(new UWPDefaultPersistedStorage(), remotePushRegistrationService, pushTagsProvider, remoteNotificationsPresenter)
 {
 }
コード例 #5
0
        public static void HandlePushRelatedBackgroundActivation(BackgroundActivatedEventArgs args, IUniversalWindowsRemoteNotificationsPresenter notificationsPresenter, INotificationsService notificationsService)
        {
            PushServicesExtensions.SetupNotificationsIfNeeded(notificationsService, notificationsPresenter);
            if (args.TaskInstance.Task.Name == PushBackgroundTaskNotificationServiceDecorator.BackgroundTaskName)
            {
                notificationsPresenter.HandleNotification((args.TaskInstance.TriggerDetails as RawNotification).Content);
            }

            if (args.TaskInstance.Task.Name == PushInvalidateRegistrationAppUpdateBackgroundTaskNotificationsServiceDecorator.BackgroundTaskName)
            {
                HandleAppUpdateBackgroundActivation(args, notificationsService);
            }
        }