private static void Disable() { if (_channel != null) { try { CurrentStatus = Status.Off; _channel.Close(); } catch (Exception ex) { Debug.WriteLine("Error closing push channel: " + ex.Message); } } }
public void unregister(string options) { Options unregisterOptions; if (!TryDeserializeOptions(options, out unregisterOptions)) { SendError(JSONError); return; } HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(unregisterOptions.WP8.ChannelName); if (pushChannel != null) { pushChannel.UnbindToShellTile(); pushChannel.UnbindToShellToast(); pushChannel.Close(); pushChannel.Dispose(); SendEvent("Channel " + unregisterOptions.WP8.ChannelName + " is closed!"); } else { SendError(MissingChannelError); } }
/// <summary> /// Closes the push notification channel. /// </summary> public void StopListeningToPushNotification() { if (channel != null && channel.ChannelUri != null) { channel.Close(); } }
// ===========================这个是推送发的信息 //====================下面是推送 Uri private void getUri() { httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }
public void OpenChannel() { HttpNotificationChannel notificationChannel1 = this.TryFindChannel(); if (notificationChannel1 != null && notificationChannel1.ChannelUri == null) { notificationChannel1.Close(); notificationChannel1 = null; } if (notificationChannel1 == null) { HttpNotificationChannel notificationChannel2 = new HttpNotificationChannel(VKConstants.HttpPushNotificationName, "push.vk.com"); notificationChannel2.ChannelUriUpdated += (new EventHandler <NotificationChannelUriEventArgs>(this.PushChannel_ChannelUriUpdated)); notificationChannel2.ErrorOccurred += (new EventHandler <NotificationChannelErrorEventArgs>(this.PushChannel_ErrorOccurred)); notificationChannel2.ShellToastNotificationReceived += (new EventHandler <NotificationEventArgs>(this.pushChannel_ShellToastNotificationReceived)); notificationChannel2.Open(); notificationChannel2.BindToShellToast(); notificationChannel2.BindToShellTile(); } else { notificationChannel1.ChannelUriUpdated += (new EventHandler <NotificationChannelUriEventArgs>(this.PushChannel_ChannelUriUpdated)); notificationChannel1.ErrorOccurred += (new EventHandler <NotificationChannelErrorEventArgs>(this.PushChannel_ErrorOccurred)); notificationChannel1.ShellToastNotificationReceived += (new EventHandler <NotificationEventArgs>(this.pushChannel_ShellToastNotificationReceived)); if (!(notificationChannel1.ChannelUri != null)) { return; } this.FireChannelUriUpdatedEvent(notificationChannel1.ChannelUri); } }
private void Connect(Action actionIfNotFound) { try { _channel = HttpNotificationChannel.Find(_channelName); } catch (Exception e) { Debug.WriteLine(e.ToString()); } if (_channel != null) { if (_channel.ChannelUri != null) { SubscribeToChannelEvents(); RegisterChannel(_channel.ChannelUri); SubscribeToNotifications(); } else { _channel.UnbindToShellTile(); _channel.UnbindToShellToast(); _channel.Close(); RetryChannelConnect(); } } else { actionIfNotFound(); } }
/// <summary> /// The callback for a channel error. /// </summary> private void httpChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e) { console.AddLine("Error occurred: " + e.Message); console.AddLine("Trying to reopen channel."); httpChannel.Close(); httpChannel.Open(); }
public void release() { HttpNotificationChannel channel = HttpNotificationChannel.Find(BmobWindowsPhone.PushChannel); if (channel != null) { channel.Close(); channel.Dispose(); } }
private void DisableNotifications() { if (channel == null) { return; } channel.Close(); channel.Dispose(); channel = null; }
private void CloseChannel(HttpNotificationChannel channel) { try { if (channel != null) { channel.Close(); } } catch { } }
public static void RemovePushChannel() { if (pushChannel != null) { try { pushChannel.Close(); } catch { } pushChannel = null; } }
private void Push_Unchecked(object sender, RoutedEventArgs e) { HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(ToastChannelName); appSettings["pushenabled"] = 0; appSettings.Save(); if (pushChannel != null) { pushChannel.UnbindToShellToast(); pushChannel.Close(); } }
public void Unregister() { httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { if (httpChannel.IsShellTileBound) { httpChannel.UnbindToShellTile(); } httpChannel.Close(); } onCompeted(); }
/// <summary> /// Unsubscribe from pushes at pushwoosh server /// </summary> public void UnsubscribeFromPushes() { if (_registrationService == null || _notificationChannel == null) { return; } _notificationChannel.UnbindToShellTile(); _notificationChannel.UnbindToShellToast(); PushToken = ""; _notificationChannel.Close(); _notificationChannel = null; _registrationService.Unregister(); }
/// <summary> /// This subscribes this phone for push notification with MPNS and saves the push notification url in Yapper services /// </summary> public void Subscribe() { // Try to find the push channel. HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(PushNotification.ChannelName); // If the channel was not found, then create a new connection to the push service. if (pushChannel == null || pushChannel.ChannelUri == null) { if (pushChannel != null) { pushChannel.UnbindToShellToast(); pushChannel.Close(); pushChannel.Dispose(); } pushChannel = new HttpNotificationChannel(PushNotification.ChannelName); // Register for all the events before attempting to open the channel. pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); pushChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); // Register for this notification only if you need to receive the notifications while your application is running. pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); pushChannel.Open(); // Bind this new channel for toast events. pushChannel.BindToShellToast(); pushChannel.BindToShellTile(); } else { // The channel was already open, so just register for all the events. pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); pushChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); // Register for this notification only if you need to receive the notifications while your application is running. pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); if (UserSettingsModel.Instance.PushNotificationSubscriptionStatus == PushNotificationSubscriptionStatus.EnabledNotSubscribed) { this.SubscribePushNotificationUrlInService(); } // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point. //System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); } }
public void DisconnectFromPushNotifications() { DisconnectFromCloud(); Unhook(); if (_channel != null) { // Removes the channel. System.Diagnostics.Debug.WriteLine("Removing the push notification channel from PNS via _channel.Close()."); _channel.Close(); _channel = null; } _info = null; }
private static void CloseChannel() { if (httpChannel == null) { return; } try { httpChannel.UnbindToShellTile(); httpChannel.UnbindToShellToast(); httpChannel.Close(); } catch (Exception ex) { ShowMessage(ex.Message, "Error Closing Channel"); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { httpChannel = HttpNotificationChannel.Find(channelName); //如果存在就删除 if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); httpChannel.ChannelUriUpdated += httpChannel_ChannelUriUpdated; httpChannel.ShellToastNotificationReceived += httpChannel_ShellToastNotificationReceived; httpChannel.HttpNotificationReceived += httpChannel_HttpNotificationReceived; httpChannel.ErrorOccurred += httpChannel_ErrorOccurred; httpChannel.Open(); httpChannel.BindToShellToast(); httpChannel.BindToShellTile(); }
/// <summary> /// This unsubscribes the phone from push notification and removes the url from the yapper service /// </summary> public void UnSubscribe() { // Try to find the push channel. using (HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(PushNotification.ChannelName)) { // If the channel was not found, then create a new connection to the push service. if (pushChannel != null) { // If the channel is not null, close the channel pushChannel.UnbindToShellToast(); pushChannel.Close(); } UserSettingsModel.Instance.PushNotificationSubscriptionStatus = PushNotificationSubscriptionStatus.Disabled; this.UnSubscribePushNotificationUrlInService(); } }
public void Stop() { FSLog.Debug(); if (NotificationChannel != null) { NotificationChannel.UnbindToShellTile(); NotificationChannel.UnbindToShellToast(); NotificationChannel.Close(); NotificationChannel.ChannelUriUpdated -= NotificationService_ChannelUriUpdated; NotificationChannel.ErrorOccurred -= NotificationService_ErrorOccurred; NotificationChannel.ShellToastNotificationReceived -= NotificationService_ShellToastNotificationReceived; Dispose(); NotificationChannel = null; } }
public void CloseChannel() { HttpNotificationChannel channel = this.TryFindChannel(); if (channel == null) { return; } try { channel.UnbindToShellToast(); channel.UnbindToShellTile(); channel.Close(); } catch (Exception) { Logger.Instance.Error("Failed to close channel"); } }
private void SetupChannel() { HttpNotificationChannel httpChannel = null; string channelName = "DemoChannel"; try { //if channel exists, retrieve existing channel httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { //If we can't get it, then close and reopen it. if (httpChannel.ChannelUri == null) { httpChannel.UnbindToShellToast(); httpChannel.Close(); SetupChannel(); return; } else { ChannelUri = httpChannel.ChannelUri; txtURI.Text = "Channel retrieved: " + httpChannel.ChannelUri; //wiring up the raw notifications event handler httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived); } } else { httpChannel = new HttpNotificationChannel(channelName); httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ExceptionOccurred); //wiring up the raw notifications event handler httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived); httpChannel.Open(); } } catch (Exception ex) { } }
private void DeleteLocalStorage() { NetworkManager.turnOffNetworkManager = true; App.MqttManagerInstance.disconnectFromBroker(false); App.ClearAppSettings(); App.WriteToIsoStorageSettings(App.IS_DB_CREATED, true); MiscDBUtil.clearDatabase(); HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(HikeConstants.pushNotificationChannelName); if (pushChannel != null) { if (pushChannel.IsShellTileBound) { pushChannel.UnbindToShellTile(); } if (pushChannel.IsShellToastBound) { pushChannel.UnbindToShellToast(); } pushChannel.Close(); } Deployment.Current.Dispatcher.BeginInvoke(() => { App.ViewModel.ClearViewModel(); try { progress.Hide(LayoutRoot); progress = null; } catch { } try { NavigationService.Navigate(new Uri("/View/WelcomePage.xaml", UriKind.Relative)); } catch { } }); }
private void SetupChannel() { HttpNotificationChannel httpChannel = null; string channelName = "DemoChannel"; try { //if channel exists, retrieve existing channel httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { //If we can't get it, then close and reopen it. if (httpChannel.ChannelUri == null) { httpChannel.UnbindToShellToast(); httpChannel.Close(); SetupChannel(); return; } else { ChannelUri = httpChannel.ChannelUri; } BindToShell(httpChannel); } else { httpChannel = new HttpNotificationChannel(channelName); httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived); httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ExceptionOccurred); httpChannel.Open(); BindToShell(httpChannel); } } catch (Exception ex) { Debug.WriteLine("An exception setting up channel " + ex.ToString()); } }
public void UpdateLiveTile(Uri liveTileUri, string liveTileTitle, int? liveTileCount, Action onComplete) { HttpNotificationChannel toastChannel = HttpNotificationChannel.Find("liveTileChannel"); if (toastChannel != null) { toastChannel.Close(); } toastChannel = new HttpNotificationChannel("liveTileChannel"); toastChannel.ChannelUriUpdated += (s, e) => { Debug.WriteLine(String.Format("Is image an absolute Uri: {0}", tileSchedule.RemoteImageUri.IsAbsoluteUri)); if (liveTileUri.IsAbsoluteUri) { toastChannel.BindToShellTile(new Collection<Uri> { liveTileUri }); } else { toastChannel.BindToShellTile(); } SendTileToPhone(e.ChannelUri, liveTileUri.ToString(), liveTileCount, liveTileTitle, () => { //Give it some time to let the update propagate Thread.Sleep(TimeSpan.FromSeconds(10)); toastChannel.UnbindToShellTile(); toastChannel.Close(); //Call the "complete" delegate if (onComplete != null) onComplete(); } ); }; toastChannel.Open(); }
public void RegisterDevice(Guid profileId) { if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator) { onCompeted(); return; } //First, try to pick up existing channel httpChannel = HttpNotificationChannel.Find(channelName); this.profileId = profileId; if (httpChannel != null) { //httpChannel.UnbindToShellTile(); //httpChannel.Close(); SubscribeToChannelEvents(); SubscribeToService(); } else { try { //Create new channel httpChannel = new HttpNotificationChannel(channelName, serviceName); SubscribeToChannelEvents(); httpChannel.Open(); } catch (Exception ex) { if (httpChannel != null) { httpChannel.Close(); } throw; } } }
//============================= 推送通知相关变量 public totalArrangement() { InitializeComponent(); if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("No network connection available!"); return; } showCurrentlist(); sendPosition(); //新添加的接收 推送信息的 httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }
private void button1_Click(object sender, RoutedEventArgs e) { HttpNotificationChannel httpChannel = null; string channelName = "NotificationTest"; httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName); httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived); httpChannel.Open(); httpChannel.BindToShellToast(); httpChannel.BindToShellTile(); }
//============================= 推送通知相关变量 public totalArrangement() { InitializeComponent(); if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("No network connection available!"); return; } showCurrentlist(); sendPosition(); //新添加的接收 推送信息的 httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }
public void onFailure(Exception value) { if ((value is ConnectionException) && ((ConnectionException)value).getCode().Equals(finalmqtt.Msg.ConnAckMessage.ConnectionStatus.BAD_USERNAME_OR_PASSWORD)) { bool isPresent = false; if (App.appSettings.Contains(App.IS_DB_CREATED)) { isPresent = true; } App.ClearAppSettings(); if (isPresent) { App.WriteToIsoStorageSettings(App.IS_DB_CREATED, true); } NetworkManager.turnOffNetworkManager = true; // stop network manager App.MqttManagerInstance.disconnectFromBroker(false); MiscDBUtil.clearDatabase(); HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(HikeConstants.pushNotificationChannelName); if (pushChannel != null) { if (pushChannel.IsShellTileBound) { pushChannel.UnbindToShellTile(); } if (pushChannel.IsShellToastBound) { pushChannel.UnbindToShellToast(); } pushChannel.Close(); } App.HikePubSubInstance.publish(HikePubSub.BAD_USER_PASS, null); } else if (hikeMqttManager.connectionStatus != HikeMqttManager.MQTTConnectionStatus.NOTCONNECTED_WAITINGFORINTERNET) { scheduler.Schedule(hikeMqttManager.connect, TimeSpan.FromSeconds(5)); } hikeMqttManager.setConnectionStatus(windows_client.Mqtt.HikeMqttManager.MQTTConnectionStatus.NOTCONNECTED_UNKNOWNREASON); }
public void unregisterForPush(string options) { PushOptions unregisterOptions; if (!TryDeserializeOptions(options, out unregisterOptions)) { DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return; } HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(unregisterOptions.ChannelName); if (pushChannel != null) { ChannelListener channelListener; if (channelListeners.TryGetValue(unregisterOptions.ChannelName, out channelListener)) { channelListener.Unsubscribe(pushChannel); channelListeners.Remove(unregisterOptions.ChannelName); } pushChannel.UnbindToShellTile(); pushChannel.UnbindToShellToast(); pushChannel.Close(); #if DEBUG Debug.WriteLine("Unregistered for push on channel " + pushChannel.ChannelName); #endif DispatchCommandResult(new PluginResult(PluginResult.Status.OK)); } else { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, MissingChannelError)); } }
private static void UnregisterFromNotificationService(Action <Exception> callback) { String channelUri = Channel.ChannelUri.ToString(); String groupString = null; if (Groups != null) { groupString = JsonConvert.SerializeObject(Groups); } if (Groups == null || Groups.Count == 0) { Channel.Close(); } Dictionary <string, object> postParameters = new Dictionary <string, object>(); postParameters.Add(NetmeraConstants.Netmera_Push_Registration_Id, channelUri); postParameters.Add(NetmeraConstants.Netmera_Push_Channel, NetmeraConstants.Netmera_Push_Type_Wp); postParameters.Add(NetmeraConstants.Netmera_Push_Apikey, NetmeraClient.securityToken); postParameters.Add(NetmeraConstants.Netmera_Push_Device_Groups, groupString); String url = NetmeraConstants.Netmera_Domain_Url + NetmeraConstants.Netmera_Push_Server_Url + NetmeraConstants.Netmera_Push_Unregister; NetmeraHttpUtils.registerUnregisterPush(url, postParameters, ex => { if (ex != null) { if (callback != null) { callback(new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "Unregister failed.")); } } else if (callback != null) { callback(ex); } }); }
public void disablePushNotifications() { try { // Try to find the push channel. pushChannel = HttpNotificationChannel.Find(channelName); if (pushChannel != null) { pushChannel.Close(); pushChannel.Dispose(); pushChannel = null; } } catch (InvalidOperationException ioException) { Utils.Tools.LogException("Cannot close the channel", ioException); } catch (ArgumentException argEcxeption) { Utils.Tools.LogException("Cannot close the channel", argEcxeption); } this.UnregisterDevice(); }
public void disablePushNotifications() { try { // Try to find the push channel. pushChannel = HttpNotificationChannel.Find(channelName); if (pushChannel != null) { pushChannel.Close(); pushChannel.Dispose(); pushChannel = null; } } catch (InvalidOperationException ioException) { Utils.Tools.LogException("Cannot close the channel", ioException); } catch (ArgumentException argEcxeption) { Utils.Tools.LogException("Cannot close the channel", argEcxeption); } this.UnregisterDevice(); }
/// <summary> /// Event handler for when a push notification error occurs. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e) { Utils.Tools.LogException((String.Format("A push notification {0} error occurred. {1} ({2}) {3}", e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)), null); if (processingError) return; processingError = true; switch (e.ErrorType) { case ChannelErrorType.ChannelOpenFailed: case ChannelErrorType.PayloadFormatError: //ChannelErrorType.ChannelOpenFailed //This error is returned when the Push Client and the Push Notification Service are unable to establish a connection //ChannelErrorType.PayloadFormatError: //This error is returned when the XML payload format or the HTTP header of the push notification is syntactically invalid. pushChannel = HttpNotificationChannel.Find(channelName); try { if (pushChannel != null) { pushChannel.Close(); pushChannel.Dispose(); pushChannel = null; } } catch (InvalidOperationException ioException) { Utils.Tools.LogException("Cannot close the channel", ioException); } catch (ArgumentException argEcxeption) { Utils.Tools.LogException("Cannot close the channel", argEcxeption); } /* UIThread.Invoke(() => { this.enablePushNotifications(); });*/ break; case ChannelErrorType.NotificationRateTooHigh: //This error is returned when the Push Client is unable to receive messages because the web service is sending too many messages at too quick a rate to a certain device. //Slow down the notifications //@TODO: send the server a signal? break; case ChannelErrorType.MessageBadContent: //This error is returned when the image reference is pointing to an HTTP image, even though the notification channel is not currently bound to a list of URIs. //This should never happen to us break; case ChannelErrorType.PowerLevelChanged: //This has been deprecated because push client no longer takes any action based on any power states break; case ChannelErrorType.Unknown: //An internal error has occurred and could not be recovered. A device reboot may be necessary. break; default: break; } processingError = false; }
private void CloseChannel(HttpNotificationChannel channel) { try { if (channel != null) channel.Close(); } catch { } }
// ===========================这个是推送发的信息 //====================下面是推送 Uri private void getUri() { httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }