public async void SendNotification()
        {
            var ctx = HttpContext.Current;

            using (var client = new HttpClient())
            {
                var list_token   = (List <TokenRegister>)ctx.Cache["token"];
                var request_data = new Notification();
                request_data.registration_ids = TokenRepository.GetInstanse().GetToken();
                NotificationMessage notificationMessage = new NotificationMessage();
                notificationMessage.message = "Hello From Firebase";
                request_data.data           = notificationMessage;

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("key", "=" + "AIzaSyAx7W0P5F6l58muel_1Qk60TUONKUkLxrY");

                /* var response = client.PostAsync("https://fcm.googleapis.com/fcm/send",
                 *              new StringContent(JsonConvert.SerializeObject(request).ToString(),
                 *              System.Text.Encoding.UTF8, "application/json"))
                 *             .Result;*/

                using (StringContent jsonContent = new StringContent(JsonConvert.SerializeObject(request_data)))
                {
                    jsonContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    using (HttpResponseMessage response = await client.PostAsync("https://fcm.googleapis.com/fcm/send", jsonContent))
                    {
                        var reponseString = await response.Content.ReadAsStringAsync();
                    }
                }
            }
        }
Example #2
0
 public static TokenRepository GetInstanse()
 {
     if (tokenRegisterRepository == null)
     {
         tokenRegisterRepository = new TokenRepository();
     }
     return(tokenRegisterRepository);
 }