MartinP MartinP - 2 years ago 212
iOS Question

How to create call dialog from UIAlertController in xamarin ios

Hi Very new to IOS development in xamarin.

I want to make call from

. below is code I am trying to make call using
but something goes wrong i dont understand.

var title = "Call";
var message = "1234567788";

var alertCotroller = UIAlertController.Create (title, message, UIAlertControllerStyle.Alert);

// Create the actions.
alertCotroller.AddAction(UIAlertAction.Create (cancelButtonTitle, UIAlertActionStyle.Cancel, alertAction =>
Console.WriteLine ("The 'Okay/Cancel' alert's cancel action occured."));

alertCotroller.AddAction(UIAlertAction.Create ("Call", UIAlertActionStyle.Default, alertAction =>UIApplication.SharedApplication.OpenUrl(new NSUrl("tel:"+message)) ));

PresentViewController (alertCotroller, true, null);

enter image description here

I just want to make call to message number, using

Answer Source

It's not possible to test Phone call on simulator.

If you are testing in a real device. Try this:

UIApplication.SharedApplication.OpenUrl(new NSUrl("tel://" + message));

If you want to prompt the user instead of calling directly you could use:

UIApplication.SharedApplication.OpenUrl(new NSUrl("telprompt://" + message));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download