Tuesday, October 4, 2011

Dialing a phone number from an iOS FireMonkey application

Q: How do you dial a phone number from an iOS application?
A: You open a URL with the following format - tel://123456789

Below is a very simple Delphi iOS unit that will do the trick.

Notice the {$IFDEF FPC} blocks that ensure that the application also compiles and is "testable" on Windows.

Enjoy!
unit Unit1;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$ENDIF}

interface

uses
SysUtils, Types, UITypes, Classes, Variants, FMX_Types, FMX_Controls, FMX_Forms,
FMX_Dialogs
{$IFDEF FPC}
, iPhoneAll
{$ENDIF}
;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
// Dial a phone number
{$IFDEF FPC}
UIApplication.sharedApplication.openUrl(NSUrl.URLWithString(NSSTR(PChar('tel://18005551212'))));
{$ENDIF}
end;

end.

4 comments: