public async static Task CheckNewInstallationID(string InstallationID) { if (ApplicationSettings.InstallationID != InstallationID && ApplicationSettings.InstallationID != "") { await Webservices.UnregisterPush(ApplicationSettings.InstallationID); } }
async void btnSave_Clicked(object sender, System.EventArgs e) { if (String.IsNullOrEmpty(entURL.Text)) { MessagingCenter.Send <SettingsPage>(this, "URLChanged"); } else { string sURL = entURL.Text.ToLower(); sURL = sURL.Replace("https", ""); //sURL = sURL.Replace("HTTPS", ""); sURL = sURL.Replace("http", ""); //sURL = sURL.Replace("HTTP", ""); sURL = sURL.Replace("://", ""); sURL = "https://" + sURL; //added on 3/25/17 by aditmer to resolve issue caused by trailing / var s = sURL.Substring(sURL.Length - 1); if (s == "/") { sURL = sURL.Substring(0, sURL.Length - 1); } if (sURL != ApplicationSettings.URL) { MessagingCenter.Send <SettingsPage>(this, "URLChanged"); if (ApplicationSettings.InstallationID != "") { await Webservices.UnregisterPush(ApplicationSettings.InstallationID); } } ApplicationSettings.URL = sURL; ApplicationSettings.InfoNotifications = swInfo.IsToggled; ApplicationSettings.AlertNotifications = swAlert.IsToggled; ApplicationSettings.AnouncementNotifications = swAnouncement.IsToggled; ApplicationSettings.VolumeSliderVisible = swVolume.IsToggled; MessagingCenter.Send <SettingsPage>(this, "VolumeSlider"); Navigation.PopModalAsync(true); await Webservices.GetStatusJson(sURL); if ((ApplicationSettings.AzureTag != "") && (Device.RuntimePlatform != Device.UWP)) { //ApplicationSettings.AzureTag = azureTag; RegisterRequest registration = new RegisterRequest(); //registration.deviceToken = DependencyService.Get<IPushNotifications>().GetDeviceToken(); registration.platform = Device.RuntimePlatform; registration.settings = new RegistrationSettings(); registration.settings.info = ApplicationSettings.InfoNotifications; registration.settings.alert = ApplicationSettings.AlertNotifications; registration.settings.announcement = ApplicationSettings.AnouncementNotifications; //If all switches are turned off for notifications, then Unregister bool bUnregister = true; //Loops through all properties of the RegistrationSettings to see if ALL of them are false Type t = typeof(RegistrationSettings); foreach (PropertyInfo propertyInfo in t.GetRuntimeProperties()) { bool bProp = Convert.ToBoolean(propertyInfo.GetValue(registration.settings)); if (bProp == true) { bUnregister = false; } } if (bUnregister) { //added on 1/3/16 by aditmer to prevent the unsubscribe webservice call when no InstallationID exists. if (ApplicationSettings.InstallationID != string.Empty) { //if UnregisterPush does NOT return an empty string, display the error message string response = await Webservices.UnregisterPush(ApplicationSettings.InstallationID); if (response != "") { await DisplayAlert("Error", response, "Ok"); } //added on 1/3/16 by aditmer to remove the InstallationID after unsubscribing. ApplicationSettings.InstallationID = string.Empty; } } else { if (ApplicationSettings.InstallationID == "") { DependencyService.Get <IPushNotifications>().Register(registration); } else { registration.deviceToken = ApplicationSettings.DeviceToken; registration.installationId = ApplicationSettings.InstallationID; await Webservices.RegisterPush(registration); } } } else //azuretag == "" (it's not in the enable string) { //if they registered for any type of notification, but don't have an AzureTag if (ApplicationSettings.InfoNotifications || ApplicationSettings.AlertNotifications || ApplicationSettings.AnouncementNotifications) { MessagingCenter.Send(this, "No AzureTag"); //Device.BeginInvokeOnMainThread(async () => // { // await DisplayAlert("Error", "Your Nightscout website does not have azurepush enabled. Please ensure you have updated your Nightscout website and added the azurepush string to your enable variable.", "Ok"); // }); } } } }