public override async void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { Hub = new SBNotificationHub(PushNotificationConstants.ListenConnectionString, PushNotificationConstants.NotificationHubName); await PushNotificationHelper.UpdateCurrentCountryTag(); // update registration with Azure Notification Hub Hub.UnregisterAll(deviceToken, (error) => { if (error != null) { Debug.WriteLine($"Unable to call unregister {error}"); return; } var tags = new NSSet(PushNotificationConstants.SubscriptionTags); Hub.RegisterNative(deviceToken, tags, (errorCallback) => { if (errorCallback != null) { Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}"); UserDialogs.Instance.Toast("Error Registering to Push Notifications"); } }); var templateExpiration = DateTime.Now.AddDays(120) .ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US")); Hub.RegisterTemplate(deviceToken, "defaultTemplate", PushNotificationConstants.APNTemplateBody, templateExpiration, tags, (errorCallback) => { if (errorCallback != null) { if (errorCallback != null) { Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}"); UserDialogs.Instance.Toast("Error Registering to Push Notifications template"); } } }); }); }
private async Task SendRegistrationToServer(string token) { try { NotificationHub hub = new NotificationHub(PushNotificationConstants.NotificationHubName, PushNotificationConstants.ListenConnectionString, this); // Get countryName for subscription tags await PushNotificationHelper.UpdateCurrentCountryTag(); // register device with Azure Notification Hub using the token from FCM Registration registration = hub.Register(token, PushNotificationConstants.SubscriptionTags); // subscribe to the SubscriptionTags list with a simple template. string pnsHandle = registration.PNSHandle; TemplateRegistration templateReg = hub.RegisterTemplate(pnsHandle, "defaultTemplate", PushNotificationConstants.FCMTemplateBody, PushNotificationConstants.SubscriptionTags); } catch (Exception e) { Log.Error(PushNotificationConstants.DebugTag, $"Error registering device: {e.Message}"); } }