How to reference NFCNDEFReaderSession from IOSapi.CoreNFC in Delphi FMX App

  

I try to include some NFC reading functionality in my Delphi IOS 64bit App. (RAD Studio 10.3.2).

But I cannot find the right way to reference NFCNDEFReaderSession.

All results in the message ObjectiveC class NFCNDEFReaderSession could not be found.

uses
System.SysUtils,
Macapi.ObjectiveC,
iOSapi.Foundation,
iOSapi.CoreNFC,
FMX.Helpers.iOS;

type

//…..
//from IOapi.CoreNFC only for information
NFCNDEFReaderSessionClass = interface(NFCReaderSessionClass)
[‘{8F8EFAB7-FEC0-4DC8-ABD2-669A639617E4}’]
end;

NFCNDEFReaderSession = interface(NFCReaderSession)
[‘{11F096EA-B10B-4566-909F-5C72A930084A}’]
procedure setReadingAvailable(readingAvailable: Boolean); cdecl;
function readingAvailable: Boolean; cdecl;
function initWithDelegate(delegate: Pointer; queue: dispatch_queue_t;
invalidateAfterFirstRead: Boolean): Pointer { instancetype }; cdecl;
end;

//…..

TNFCNDEFReaderSession = class(TOCGenericImport<NFCNDEFReaderSessionClass,
NFCNDEFReaderSession>)
end;

TNFCNDEFReaderSessionDelegate = class(TOCLocal,NFCNDEFReaderSessionDelegate)
public
procedure readerSessionDidInvalidateWithError(session: NFCNDEFReaderSession;
didInvalidateWithError: NSError); cdecl;
procedure readerSessionDidDetectNDEFs(session: NFCNDEFReaderSession;
didDetectNDEFs: NSArray); cdecl;
end;

TIOS_NFCUtil = class
private
sessionDelegate: TNFCNDEFReaderSessionDelegate;
session : NFCNDEFReaderSession;
public
constructor create;
end;
var
IOS_NFCUtil: TIOS_NFCUtil;

implementation
uses FMX.DialogService;
{ TIOS_NFCUtil }

constructor TIOS_NFCUtil.create;
var
rsession: NFCReaderSession;
begin
try
sessionDelegate := TNFCNDEFReaderSessionDelegate.Create; // Create OK
rsession := TNFCReaderSession.Create;
// Session := TNFCNDEFReaderSession.Create;
session := TNFCNDEFReaderSession.Wrap(TNFCNDEFReaderSession.Alloc.initWithDelegate(sessionDelegate,nil, false));

except
on e: Exception do
begin
TDialogService.showmessage(e.Message);
end;
end;
end;

How to initialize the NFC session?
—>
session:=NFCNDEFReaderSession.Wrap(TNFCNDEFReaderSession.Alloc.initWithDelegate(sessionDelegate,nil, false));

Checked out to initialize NFCNDEFReaderSession inside TNFCNDEFReaderSessionDelegate class, but ObjectiveC class is still not found

type
TNFCNDEFReaderSessionDelegate = class(TOCLocal,NFCNDEFReaderSessionDelegate)
private
session: NFCNDEFReaderSession;
public
procedure InitReaderSession;
procedure readerSessionDidInvalidateWithError(session: NFCNDEFReaderSession;
didInvalidateWithError: NSError); cdecl;
procedure readerSessionDidDetectNDEFs(session: NFCNDEFReaderSession;
didDetectNDEFs: NSArray); cdecl;
end;

procedure TNFCNDEFReaderSessionDelegate.InitReaderSession;
var
step: Integer;
begin
try
step := 0;
//session := TNFCNDEFReaderSession.Create;
TNFCNDEFReaderSession.Wrap(TNFCNDEFReaderSession.Alloc.initWithDelegate(self,nil,false));
step := 1;
(*if assigned(session) then
begin
step := 2;
session.initWithDelegate(self,nil,false);
step := 3;
session.beginSession;
step := 4;
end; *)
except
on e: Exception do
begin
TDialogService.showmessage(e.Message+ ‘ ‘ + step.ToString);
end;
end;
end;

MessageBox: ObjectiveC class not found (step 0) also in case of session := TNFCNDEFReaderSession.Create;

Comments are closed.