Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var translatedNumber = string.Empty;

            translateButton.TouchUpInside += delegate
            {
                var translator = new PhoneTranslator();
                translatedNumber = translator.ToNumber(phoneNumberText.Text);

                if (string.IsNullOrEmpty(translatedNumber))
                {
                    // No hay número a llamar
                    callButton.SetTitle("Llamar", UIControlState.Normal);
                    callButton.Enabled = false;
                }
                else
                {
                    // Hay un posible número telefónico a llamar
                    callButton.SetTitle($"Llamar a {translatedNumber}", UIControlState.Normal);
                    callButton.Enabled = true;
                }
            };

            callButton.TouchUpInside += delegate
            {
                var url = new Foundation.NSUrl($"tel:{translatedNumber}");

                // Utilizar el manejador de URL con el prefijo tel: para invocar a la
                // aplicación Phone de Apple, de lo contrario mostrar un diálogo de alerta.

                if (!UIApplication.SharedApplication.OpenUrl(url))
                {
                    var alert = UIAlertController.Create("No soportado", "El esquema 'tel:' no es soportado en este dispositivo",
                                                         UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
            };

            // Perform any additional setup after loading the view, typically from a nib.
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            var TranslatedNumber = string.Empty;

            TranslateButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                PhoneNumberText.ResignFirstResponder();

                var Translator = new PhoneTranslator();
                TranslatedNumber = Translator.ToNumber(PhoneNumberText.Text);

                if (string.IsNullOrWhiteSpace(TranslatedNumber))
                {
                    CallButton.SetTitle("Llamar", UIControlState.Normal);
                    CallButton.Enabled = false;
                }
                else
                {
                    CallButton.SetTitle($"Llamar al {TranslatedNumber}", UIControlState.Normal);
                    CallButton.Enabled = true;
                }
            };

            CallButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                PhoneNumberText.ResignFirstResponder();

                var URL = new Foundation.NSUrl($"tel:{TranslatedNumber}");
                if (!UIApplication.SharedApplication.OpenUrl(URL))
                {
                    var Alert = UIAlertController.Create("No soportado",
                                                         "El esquema 'tel:' no es soportado en este dispositivo",
                                                         UIAlertControllerStyle.Alert);
                    Alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(Alert, true, null);
                }
            };
        }