Dialing the Phone by URI

PDF for offline use
Sample Code:
Related SDKs:

Let us know how you feel about this

Translation Quality


0/250

iOS apps utilize uniform resource locators (URLs), a form of uniform resource identifiers (URIs), to access schemes that integrate with system apps. The tel URL scheme launches the Phone app and dials the number contained in the NSUrl.

Recipe

Dial By URI

  1. First, we must generate a NSUrl from the string "tel:" appended to the number we want to dial. For this example, lets place the following code in the CallButton TouchUpInside event handler:
var url = new NSUrl ("tel:" + PhoneTextField.Text);
  1. To create a scheme to access the Phone app, we would place the following code after we generate our NSUrl variable:
UIApplication.SharedApplication.OpenUrl (url);
  1. Since emulators don't support the system Phone app, we should instead attempt to create our scheme inside the following conditional statement:
if (!UIApplication.SharedApplication.OpenUrl (url)) {
        var av = new UIAlertView ("Not supported",
          "Scheme 'tel:' is not supported on this device",
          null,
          "OK",
          null);
        av.Show ();
    };

If the scheme cannot be generated, we alert the user using a UIAlertView.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.