예제 #1
0
        public string EnviarNotificacao(string sCodigoGCM)
        {
            string sRetorno  = "OK";
            string codigoGCM = "\"" + sCodigoGCM + "\"";

            try
            {
                string postData = "{ \"registration_ids\" : [" + codigoGCM + "],   \"data\" : " + JsonConvert.SerializeObject(this) + " }";
                sRetorno = Util_GCM.SendGCMNotification(postData);
            }
            catch (Exception)
            {
                throw;
            }
            return(sRetorno);
        }
예제 #2
0
        public string EnviarNotificacaoTodos()
        {
            List <Pessoa> lista = new List <Pessoa>();

            lista = Pessoa.BuscarListaPessoas();
            string sRetorno  = "OK";
            string codigoGCM = "";

            if (lista.Count == 1)
            {
                foreach (Pessoa item in lista)
                {
                    codigoGCM += "\"" + item.Gcm + "\",";
                    try
                    {
                        string postData = "{ \"registration_ids\" : [" + codigoGCM + "],   \"data\" : " + JsonConvert.SerializeObject(this) + " }";
                        sRetorno = Util_GCM.SendGCMNotification(postData);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            else
            {
                int iCont = 0;

                foreach (Pessoa item in lista)
                {
                    iCont++;
                    codigoGCM += "\"" + item.Gcm + "\",";
                    if (iCont == 999)
                    {
                        try
                        {
                            string postData = "{ \"registration_ids\" : [" + codigoGCM + "],   \"data\" : " + JsonConvert.SerializeObject(this) + " }";
                            sRetorno  = Util_GCM.SendGCMNotification(postData);
                            codigoGCM = "";
                            iCont     = 0;
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }

                if (codigoGCM != "")
                {
                    try
                    {
                        string postData = "{ \"registration_ids\" : [" + codigoGCM + "],   \"data\" : " + JsonConvert.SerializeObject(this) + " }";
                        sRetorno = Util_GCM.SendGCMNotification(postData);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            return(sRetorno);
        }