Beispiel #1
0
        /// <summary>
        /// Отписывает устройство от получения Push-уведомлений
        /// </summary>
        public async Task UnregisterDevice()
        {
            if (channel == null)
            {
                channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
            }

            var parameters = new Dictionary <string, string>
            {
                ["device_id"] = deviceInformationService.GetHardwareID()
            };
            var request = new Request <VKOperationIsSuccess>("account.unregisterDevice", parameters)
            {
                HttpMethod = HttpMethod.POST
            };
            var response = await vkService.ExecuteRequestAsync(request);

            if (!response.IsSuccess)
            {
                throw new Exception("Не удалось отменить регистрацию устройства");
            }

            channel.Close();
            channel.PushNotificationReceived -= Channel_PushNotificationReceived;
            channel       = null;
            WNSChannelUri = null;
        }
Beispiel #2
0
 public void closeNotificationService()
 {
     //关闭通道
     if (channel != null)
     {
         channel.Close();
         channel = null;
     }
 }
Beispiel #3
0
        public async void UnBind()
        {
            PushNotificationChannel pushChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            if (pushChannel != null)
            {
                pushChannel.PushNotificationReceived -= pushChannel_PushNotificationReceived;
                pushChannel.Close();
                Global.Current.LocalSettings.SaveData(conChannelUriKey, string.Empty);
            }
        }
Beispiel #4
0
        private void DisableNotifications()
        {
            lock (sync)
            {
                if (channel == null)
                {
                    return;
                }

                channel.Close();
                channel = null;
            }
        }
        private static async void CloseWNSChannel()
        {
            var settings = ApplicationData.Current.LocalSettings;

            if (settings.Values.ContainsKey(HAS_WNS_CHANNEL_KEY) && (bool)settings.Values[HAS_WNS_CHANNEL_KEY])
            {
                try
                {
                    PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

                    channel.Close();
                    ApplicationData.Current.LocalSettings.Values[HAS_WNS_CHANNEL_KEY] = false;
                }
                catch {}
            }
        }
        private void CloseChannel_Click(Object sender, RoutedEventArgs e)
        {
            PushNotificationChannel currentChannel = rootPage.Channel;

            if (currentChannel != null)
            {
                // Closing the channel prevents all future cloud notifications from
                // being delivered to the application or application related UI
                currentChannel.Close();
                rootPage.Channel = null;

                rootPage.NotifyUser("Channel closed", NotifyType.StatusMessage);
            }
            else
            {
                rootPage.NotifyUser("Channel not open", NotifyType.ErrorMessage);
            }
        }
        public override async Task <bool> UnregisterAsync(CancellationToken cancellationToken)
        {
            var push = ((MobileServiceClient)Client).GetPush();


            if (_currentChannel != null)
            {
                await push.UnregisterAsync();

                _currentChannel.PushNotificationReceived -= OnPushNotificationReceived;
                _currentChannel.Close();
                _currentChannel = null;

                await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Configuration.NotificationHandler?.OnUnregistrationSucceeded());
            }

            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// Unsubscribe from pushes at pushwoosh server
        /// </summary>
        public void UnsubscribeFromPushes(EventHandler <string> success, EventHandler <string> failure)
        {
            if (_notificationChannel != null)
            {
                _notificationChannel.Close();
                _notificationChannel = null;
            }

            PushToken = "";
            UnregisterRequest request = new UnregisterRequest {
                AppId = AppID
            };

            PushwooshAPIServiceBase.InternalSendRequestAsync(request, (obj, arg) => { if (success != null)
                                                                                      {
                                                                                          success(this, null);
                                                                                      }
                                                             }, failure);
        }
Beispiel #9
0
        public async Task CloseNotificationsChannel()
        {
            if (_channel != null)
            {
                try
                {
                    UpdateStatusMessage("1. Deleting User Channel URI from server");

                    //1. Remove channel from app server so it no longer sends notifications to this channel
                    using (var client = new HttpClient())
                    {
                        var result = await client.DeleteAsync(string.Format("{0}/{1}/{2}/{3}", K_SERVERURL, _appId, _clientId, _tileId));

                        if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                        {
                            UpdateStatusMessage(string.Format("   Channel URI successfully deleted from Notification App Server."));
                        }
                        else
                        {
                            UpdateStatusMessage(string.Format("   Could not delete Channel from Notification App Server - {0}", result.StatusCode.ToString()));
                        }
                    }

                    UpdateStatusMessage(string.Format("2. Closing Channel"));

                    //2. Close the channel
                    _channel.Close();
                    _channel = null;

                    UpdateStatusMessage(string.Format("   Channel successfully closed"));
                }
                catch (Exception ex)
                {
                    UpdateStatusMessage(string.Format("   Error occured please see exception detail: {0}", ex.ToString()));
                }
            }
            else
            {
                UpdateStatusMessage("No channel is open.");
            }
        }
Beispiel #10
0
        public static async void Stop()
        {
            if (_notificationChannel != null)
            {
                _notificationChannel.PushNotificationReceived -= PushNotificationReceived;
                _notificationChannel.Close();
                _notificationChannel = null;
            }

            try
            {
                var result = await ServiceLocator.Vkontakte.Account.UnregisterDevice(DeviceHelper.GetDeviceId());

                if (result)
                {
                    Debug.WriteLine("Push notifications unregistered");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to unregister device for push notifications");
            }
        }
Beispiel #11
0
        /// <summary>
        /// Explicitly invalidates this channel. Any notifications pushed to this channel after this method is called are not delivered
        /// </summary>
        public void Close()
        {
#if NETFX_CORE
            _pushNotificationChannel.Close();
#endif
        }
 public void Close() => _pushNotificationChannel.Close();