I am using Delphi 11 and using iOS 15.2.1. When I use the following code similar to the TMS pdf print example, the app will crash if you just invoke the print dialog then cancel it. Message shown is "Exception Object Address 0x0" and stop in the CPU window. Any ideas what to look at here? This was working on D10.4 iOS 13.4
Thanks
Tom
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.Platform,
FMX.Controls.Presentation, FMX.StdCtrls, iOSapi.UIKit, FMX.TMSNativeUIWebView,
iOSApi.Foundation, MacApi.ObjectiveC, iOSApi.CocoaTypes,
FMX.TMSNativeUIBaseControl;
type
TUIPrintInteractionCompletionHandler = procedure(printInteractionController: Pointer; completion: Pointer; error: PPointer) of object; cdecl;
UIPrintInteractionControllerClass = interface(NSObjectClass)
['{D3566B82-3014-40C6-B7E3-DFC22AF39319}']
function canPrintData(data: NSData): Boolean; cdecl;
function canPrintURL(url: NSURL): Boolean; cdecl;
function isPrintingAvailable: Boolean; cdecl;
function printableUTIs: NSSet; cdecl;
function sharedPrintController: Pointer; cdecl;
end;
UIPrintInteractionController = interface(NSObject)
['{0FEF6AA7-132B-41C8-BB12-045C43027D4B}']
function delegate: Pointer; cdecl;
procedure dismissAnimated(animated: Boolean); cdecl;
function printFormatter: UIPrintFormatter; cdecl;
function printInfo: UIPrintInfo; cdecl;
function printPageRenderer: UIPrintPageRenderer; cdecl;
function printPaper: UIPrintPaper; cdecl;
function printingItem: Pointer; cdecl;
function printingItems: NSArray; cdecl;
procedure setDelegate(delegate: Pointer); cdecl;
procedure setPrintFormatter(printFormatter: UIPrintFormatter); cdecl;
procedure setPrintInfo(printInfo: UIPrintInfo); cdecl;
procedure setPrintPageRenderer(printPageRenderer: UIPrintPageRenderer); cdecl;
procedure setPrintingItem(printingItem: Pointer); cdecl;
procedure setPrintingItems(printingItems: NSArray); cdecl;
procedure setShowsPageRange(showsPageRange: Boolean); cdecl;
procedure presentAnimated(animated: Boolean; completionHandler: TUIPrintInteractionCompletionHandler); cdecl;
function showsPageRange: Boolean; cdecl;
end;
TUIPrintInteractionController = class(TOCGenericImport<UIPrintInteractionControllerClass, UIPrintInteractionController>) end;
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
iOSBrowser: TTMSFMXNativeUIWebView;
procedure Button1Click(Sender: TObject);
procedure PrintCompleted(printInteractionController: Pointer; completion: Pointer; error: PPointer); cdecl;
procedure FormShow(Sender: TObject);
private
procedure PrintSheetiOS(useDelay: Boolean);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
iOSBrowser: TTMSFMXNativeUIWebView;
pic: UIPrintInteractionController;
implementation
{$R *.fmx}
procedure TForm1.PrintSheetiOS(useDelay: Boolean);
var
pi: UIPrintInfo;
ppc: UIPrinterPickerController;
begin
pi := TUIPrintInfo.Wrap(TUIPrintInfo.OCClass.printInfo);
pi.setOutputType(UIPrintInfoOutputGeneral);
pi.setJobName(NSSTR('TestPrint')); //iOSBrowser.WebView.request.URL.absoluteString
pi.setOrientation(UIPrintInfoOrientationPortrait);
pi.setDuplex(UIPrintInfoDuplexLongEdge);
pic := TUIPrintInteractionController.Wrap(TUIPrintInteractionController.OCClass.sharedPrintController);
pic.setPrintInfo(pi);
pic.setShowsPageRange(True);
pic.setPrintFormatter(iOSBrowser.WebView.viewPrintFormatter);
pic.presentAnimated(True, PrintCompleted);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintSheetiOS(True);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
iOSBrowser.LoadHTMLString('<html><p><b>Test iOS Printing</b></p></html>');
end;
procedure TForm1.PrintCompleted(printInteractionController,
completion: Pointer; error: PPointer);
begin
if Boolean(completion) then
begin
end;
end;
end.