async void SendRegistrationToServer(string token) { if (registerRequest != null) { registerRequest.deviceToken = token;//.Split(':')[1]; registerRequest.installationId = token.Split(':')[0]; await Webservices.RegisterPush(registerRequest); } }
//// And do this, instead of creating a seperate delegate //#region IUNUserNotificationCenterDelegate //[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")] //public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) //{ // var manager = BITHockeyManager.SharedHockeyManager; // manager.MetricsManager.TrackEvent("iOS Notification Ack"); // // Take action based on Action ID // switch (response.ActionIdentifier) // { // case "snooze": // AckRequest ack = new AckRequest(); // var userInfo = response.Notification.Request.Content.UserInfo; // if (userInfo.ContainsKey(new NSString("level"))) // { // ack.level = userInfo.ValueForKey(new NSString("level")) as NSString; // //ack.Level = level.Int32Value; // } // if (userInfo.ContainsKey(new NSString("group"))) // { // ack.group = (userInfo.ValueForKey(new NSString("group")) as NSString).ToString(); // } // if (userInfo.ContainsKey(new NSString("key"))) // { // ack.key = (userInfo.ValueForKey(new NSString("key")) as NSString).ToString(); // } // ack.time = 15; // Webservices.SilenceAlarm(ack); // break; // // default: // // Take action based on identifier // //switch (response.ActionIdentifier) // //{ // // case UNActionIdentifier.Default: // //// Handle default // //... // //break; // // case UNActionIdentifier.Dismiss: // // Handle dismiss // //... // //break; // //} // //break; // } // // Inform caller it has been handled // completionHandler(); //} //#endregion public async override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { string s = deviceToken.Description.Replace("<", "").Replace(">", "").Replace(" ", ""); //Byte[] tokenBytes = deviceToken.Bytes; //for (int i = 0; i < 8;i++) //{ // s += String.Format("%08x%08x%08x%08x%08x%08x%08x%08x", deviceToken.Bytes[i]) //} RegisterRequest registration = new RegisterRequest(); //added on 1/7/17 by aditmer to unregister and reregister if the app gets a new device token //if (s != ApplicationSettings.InstallationID && ApplicationSettings.InstallationID != "") //{ // await Webservices.UnregisterPush(ApplicationSettings.InstallationID); //} await CheckInstallationID.CheckNewInstallationID(s); if (PushNotificationsImplementation.registerRequest != null) { registration = PushNotificationsImplementation.registerRequest; } else { registration.platform = Xamarin.Forms.Device.RuntimePlatform.ToString(); registration.settings = new RegistrationSettings(); registration.settings.info = ApplicationSettings.InfoNotifications; registration.settings.alert = ApplicationSettings.AlertNotifications; registration.settings.announcement = ApplicationSettings.AnouncementNotifications; } registration.deviceToken = s; ApplicationSettings.DeviceToken = s; await Webservices.RegisterPush(registration); //Commented out on 11/29/16 by aditmer so we can register for notifications on the server //Hub = new SBNotificationHub(Constants.ConnectionString, Constants.NotificationHubPath); //Hub.UnregisterAllAsync(deviceToken, (error) => //{ // if (error != null) // { // Console.WriteLine("Error calling Unregister: {0}", error.ToString()); // return; // } //}); // //adds a tag for the current Nightscout URL in the App Settings // NSSet tags = new NSSet(ApplicationSettings.AzureTag); // //const string template = "{\"aps\":{\"alert\":\"$(message)\"},\"request\":\"$(requestid)\"}"; // const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(message)\",\"sound\":\"$(sound)\"},\"eventName\":\"$(eventName)\",\"group\":\"$(group)\",\"key\":\"$(key)\",\"level\":\"$(level)\",\"title\":\"$(title)\"}"; // //var alert = new JObject( // //new JProperty("aps", new JObject(new JProperty("alert", notificationText))), // //new JProperty("inAppMessage", notificationText)) // //.ToString(Newtonsoft.Json.Formatting.None); // //JObject templates = new JObject(); // //templates["genericMessage"] = new JObject // //{ // // {"body", templateBodyAPNS} // //}; // var expiryDate = DateTime.Now.AddDays(90).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US")); //Hub.RegisterTemplateAsync(deviceToken,"nightscout",templateBodyAPNS, // expiryDate,tags,(errorCallback) => // { // if (errorCallback != null) // Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString()); // }); }