unit iOSForm;

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

interface
uses
{$IFDEF FPC}
  iPhoneAll,
{$ELSE}
  Windows, ShellAPI,
{$ENDIF}
  SysUtils, Types, UITypes, Classes, Variants, FMX_Types, FMX_Controls, FMX_Forms,
  FMX_Dialogs, FMX_Layouts, FMX_Edit;

type
  TfrmiOS = class(TForm)
    btnURL: TButton;
    btnDial: TButton;
    btnEmail: TButton;
    edURL: TEdit;
    edDial: TEdit;
    edEmail: TEdit;
    GridLayout1: TGridLayout;
    procedure btnURLClick(Sender: TObject);
    procedure btnDialClick(Sender: TObject);
    procedure btnEmailClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmiOS: TfrmiOS;

implementation

{$R *.lfm}

procedure TfrmiOS.btnDialClick(Sender: TObject);
begin
  {$IFDEF FPC}
  UIApplication.sharedApplication.
    openUrl(NSUrl.URLWithString(NSSTR(PChar('tel://'+edDial.Text))));
  {$ENDIF}
end;

procedure TfrmiOS.btnEmailClick(Sender: TObject);
var
  Subject, Body: String;
  {$IFDEF FPC}
  URL: NSString;
  {$ENDIF}
begin
  Subject := 'E-mail test';
  Body := 'Hi Bob…';
  {$IFDEF FPC}
  URL := NSSTR(PChar('mailto:'+edEmail.Text+'subject='+
           Subject+'&body='+Body));
  URL := URL.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding);
  UIApplication.sharedApplication.openUrl(NSURL.URLWithString(URL));
  {$ENDIF}
end;

procedure TfrmiOS.btnURLClick(Sender: TObject);
begin
  {$IFDEF FPC}
  UIApplication.sharedApplication.
    openUrl(NSUrl.URLWithString(NSSTR(PChar('http://'+edURL.Text))));
  {$ELSE}
  ShellExecute(Handle, 'open', PWideChar('http://'+edURL.Text), nil, nil, SW_SHOW);
  {$ENDIF}
end;

end.
