I’m trying to open a URL in Delphi 12.2, Firemonkey. This is my code:
procedure OpenURL(const URL: string);
begin
try
if SharedApplication.OpenURL(StrToNSUrl(URL)) then
showmessage('success')
else
showmessage('failed');
except
on E: Exception do
showmessage('Error ' + E.Message);
end;
end;
It works fine in the simulator, but I get the ‘failed’ message when I run it on a physical iPhone 14 pro – that is, the link doesn't work, but it’s not producing an exception.
Since Delphi doesn’t run in debug mode on physical devices with recent operating systems, I can’t do any debugging.
I’m testing using since I presume this is no problem for an iPhone (in case there is some sort of security check for URLs).
I’d be very grateful for any suggestions. Thanks, Ian
I’m trying to open a URL in Delphi 12.2, Firemonkey. This is my code:
procedure OpenURL(const URL: string);
begin
try
if SharedApplication.OpenURL(StrToNSUrl(URL)) then
showmessage('success')
else
showmessage('failed');
except
on E: Exception do
showmessage('Error ' + E.Message);
end;
end;
It works fine in the simulator, but I get the ‘failed’ message when I run it on a physical iPhone 14 pro – that is, the link doesn't work, but it’s not producing an exception.
Since Delphi doesn’t run in debug mode on physical devices with recent operating systems, I can’t do any debugging.
I’m testing using https://www.apple since I presume this is no problem for an iPhone (in case there is some sort of security check for URLs).
I’d be very grateful for any suggestions. Thanks, Ian
Share Improve this question asked Mar 24 at 12:53 IanIan 1513 silver badges12 bronze badges1 Answer
Reset to default 4It's due to a change in iOS 18, that now requires the method that accepts a callback to be used, which Delphi as of 12.3, does not have an import for. This is an example of how to work around it:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OpenURLCompletion(success: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
uses
Macapi.Helpers, Macapi.ObjectiveC,
iOSapi.Foundation, iOSapi.UIKit;
type
TUIApplicationOpenURLCompletionProc = procedure(success: Boolean) of object;
UIApplicationEx = interface(UIApplication)
['{C1BE9D49-21ED-4723-90F0-0199A54D16FE}']
procedure openURL(url: NSURL; options: NSDictionary; completionHandler: TUIApplicationOpenURLCompletionProc); cdecl;
end;
TUIApplicationEx = class(TOCGenericImport<UIApplicationClass, UIApplicationEx>) end;
function SharedApplicationEx: UIApplicationEx;
begin
Result := TUIApplicationEx.Wrap(TUIApplication.OCClass.sharedApplication);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SharedApplicationEx.openURL(StrToNSUrl('https://www.embarcadero'), nil, OpenURLCompletion);
end;
procedure TForm1.OpenURLCompletion(success: Boolean);
begin
// Take action if not successful?
end;
end.