Open url in Delphi, firemonkey, for iOS - Stack Overflow

I’m trying to open a URL in Delphi 12.2, Firemonkey.This is my code:procedure OpenURL(const URL: str

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 badges
Add a comment  | 

1 Answer 1

Reset to default 4

It'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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744250879a4565160.html

相关推荐

  • Open url in Delphi, firemonkey, for iOS - Stack Overflow

    I’m trying to open a URL in Delphi 12.2, Firemonkey.This is my code:procedure OpenURL(const URL: str

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信