コード例 #1
0
        public async void BaiduBinded(object sender, BindedEventArgs e)
        {
            //PushManager.SetTags(Xamarin.Forms.Forms.Context, userMarks);

            if (hub == null)
            {
                hub = new WindowsAzure.Messaging.NotificationHub(ConfigurationSettings.HUB_NAME, ConfigurationSettings.HUB_CONNEXTION_STRING, Xamarin.Forms.Forms.Context);
            }
            await Task.Run(() =>
            {
                using (var re = hub.RegisterBaidu(e.UserID, e.ChannelID, userMarks))
                {
                    if (!string.IsNullOrEmpty(re.RegistrationId))
                    {
                        isRegisted = true;
                    }
                    else
                    {
                        isRegisted = false;
                    }
                }
            });

            NotifyMessageReceiver.Binded -= BaiduBinded;
        }
コード例 #2
0
        private void SendRegistrationToServer(string token)
        {
            try
            {
                App.DeviceId = Android.Provider.Settings.Secure.GetString(
                    Application.Context.ContentResolver,
                    Android.Provider.Settings.Secure.AndroidId);
                string[] tokens = Constants.SubscriptionTags.Append($"deviceid:{App.DeviceId}").ToArray();

                WindowsAzure.Messaging.NotificationHub hub = new WindowsAzure.Messaging.NotificationHub(Constants.NotificationHubName, Constants.ListenConnectionString, this);

                // register device with Azure Notification Hub using the token from FCM
                Registration registration = hub.Register(token, tokens);

                // subscribe to the SubscriptionTags list with a simple template.
                string pnsHandle = registration.PNSHandle;
                TemplateRegistration templateReg = hub.RegisterTemplate(pnsHandle, "defaultTemplate", Constants.FCMTemplateBody, tokens);
            }
            catch (Exception e)
            {
                Log.Error(Constants.DebugTag, $"Error registering device: {e.Message}");
            }
        }