Define a class help to create/update/delete notification registrations
Пример #1
0
        public async void Register(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
        {
            try
            {
                const string templateBodyGCM = "{\"" + HEADER_PUSH + "\":{" +
                                               "\"" + MESSAGE_PUSH + "\":\"$(messageParam)\"" +
                                               "\"" + MESSAGE_PUSH_TITLE + "\":\"$(titleParam)\"" +
                                               "\"" + IMAGE_PUSH + "\":\"$(imageParam)\"" +
                                               "}}";

                JObject templates = new JObject();
                templates["genericMessage"] = new JObject
                {
                    { "body", templateBodyGCM }
                };

                await push.RegisterAsync(RegistrationID, templates);

                Log.Info("Push Installation Id", push.InstallationId.ToString());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                // Debugger.Break();
            }
        }
Пример #2
0
        /// <summary>
        /// 進行Azure 推播中樞註冊
        /// </summary>
        /// <param name="push"></param>
        /// <param name="tags"></param>
        public async void Register(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
        {
            #region 進行Azure 推播中樞註冊
            try
            {
                // 設定要接收來自於 Azure 推播中樞的推播訊息格式
                string templateBodyGCM = "{\"data\":{\"message\":\"$(messageParam)\", \"title\":\"$(titleParam)\", \"args\":\"$(argsParam)\"}}";;

                JObject templates = new JObject();
                templates["genericMessage"] = new JObject
                {
                    { "body", templateBodyGCM }
                };

                // 註冊要接收的推播訊息格式
                await push.RegisterAsync(RegistrationID, templates);

                Log.Info("Push Installation Id", push.InstallationId.ToString());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                //Debugger.Break();
            }
            #endregion
        }
Пример #3
0
        //Registrar no Azure o App.

        public async void Register(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
        {
            try
            {
                //Cada rede tem um template específico de mensagem, o messageParam é o que vale
                //este template é cadastrado no Azure (dentro do TestSend pegamos ele)
                const string templateBodyGCM = "{\"data\":{\"message\":\"$(messageParam)\"}}";

                JObject templates = new JObject();

                templates["genericMessage"] = new JObject
                {
                    { "body", templateBodyGCM }
                };


                //RegistrationID é o id do celular
                await push.RegisterAsync(RegistrationID, templates);

                Log.Info("Push Installation Id", push.InstallationId.ToString());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                Debugger.Break();
            }
        }
Пример #4
0
 public async void Register(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
 {
     try
     {
         await push.RegisterAsync(RegistrationID);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
         Debugger.Break();
     }
 }
Пример #5
0
        public async void Register(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
        {
            try
            {
                const string template = "{\"data\":{\"message\":\"$(message)\"}}";

                await push.RegisterTemplateAsync(RegistrationID, template, "mytemplate", tags);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                Debugger.Break();
            }
        }
Пример #6
0
        public async void RegisterAsync(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
        {
            try
            {
                var installation = new DeviceInstallation
                {
                    InstallationId = Client.InstallationId,
                    Platform       = "gcm",
                    PushChannel    = RegistrationID
                };


                using (var scope = App.Container?.BeginLifetimeScope())
                {
                    (await scope?.Resolve <GrupoOfertaService>()?.CarregarGrupoDeOfertasUsuarioLogadoAsync()).Select(x => { installation.Tags.Add(x.Id); return(x); }).ToArray();
                    (await scope?.Resolve <ListaCompraService>()?.CarregarListasDeComprasUsuarioLogadoAsync()).Select(x => { installation.Tags.Add(x.Id); return(x); }).ToArray();
                    installation.Tags.Add("user:"******"{""data"":{""key"":""$(keyParam)"",""message"":""$(messageParam)""}}"
                };
                PushTemplate ofertaTemplate = new PushTemplate
                {
                    Body = @"{""data"":{""key"":""$(keyParam)"",""ofertaTitle"":""$(ofertaTitleParam)"",""ofertaDescription"":""$(ofertaDescriptionParam)"",""idOFerta"":""$(ofertaIdParam)""}}"
                };

                installation.Templates.Add("genericTemplate", genericTemplate);
                installation.Templates.Add("ofertaTemplate", ofertaTemplate);

                // Register with NH
                await Client.InvokeApiAsync <DeviceInstallation, DeviceInstallation>(
                    $"/push/installations/{Client.InstallationId}",
                    installation,
                    HttpMethod.Put,
                    new Dictionary <string, string>());

                await Client.InvokeApiAsync <string[], object>("refreshPushRegistration", installation.Tags.ToArray());

                //await push. RegisterAsync(RegistrationID, templates);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                Debugger.Break();
            }
        }
Пример #7
0
        //Part: 7 Push Notification
        public async void Register(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
        {
            try
            {
                //messageParam: is defined in edit favorite script from azure
                const string templateBodyGCM = "{\"data\":{\"message\":\"$(messageParam)\"}}";

                JObject templates = new JObject();
                templates["genericMessage"] = new JObject
                {
                    { "body", templateBodyGCM }
                };

                await push.RegisterAsync(RegistrationID, templates);
            }
            catch (Exception ex)
            {
            }
        }
Пример #8
0
        public async void Register(Microsoft.WindowsAzure.MobileServices.Push push, IEnumerable <string> tags)
        {
            try
            {
                const string templateBodyGCM = "\"data\":{\"message\":\"$(messageParam)\"}}";
                JObject      templates       = new JObject();
                templates["genericMessage"] = new JObject
                {
                    { "body", templateBodyGCM }
                };
                await push.RegisterAsync(RegistrationId, templates);

                Log.Info("Push installation ID", push.InstallationId.ToString());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                Debugger.Break();
            }
        }
		public AzureNotificationHubService_iOS ()
		{
			_mobileServiceClient = new MobileServiceClient (Helpers.Keys.AzureMobileService_URL, Helpers.Keys.AzureMobileService_KEY); 
			_push = _mobileServiceClient.GetPush ();
		}