16#import <CoreNFC/NFCReaderSession.h>
17#import <CoreNFC/NFCNDEFReaderSession.h>
18#import <CoreNFC/NFCTagReaderSession.h>
24 auto notifier = std::make_unique<QNfcNdefNotifier>();
26 if (@available(
iOS 13, *))
30 this, &QNearFieldManagerPrivateImpl::onTagDiscovered,
33 this, &QNearFieldManagerPrivateImpl::onDidInvalidateWithError,
41 this, &QNearFieldManagerPrivateImpl::onTagDiscovered,
44 this, &QNearFieldManagerPrivateImpl::onDidInvalidateWithError,
47 qCWarning(QT_IOS_NFC,
"Failed to allocate NDEF reading session's delegate");
57 if (@available(
iOS 13, *))
64 dispatch_sync(
queue, ^{
74 switch (accessMethod) {
77 return NFCNDEFReaderSession.readingAvailable;
79 if (@available(
iOS 13, *))
80 return NFCTagReaderSession.readingAvailable;
94 switch (accessMethod) {
99 if (@available(
iOS 13, *))
100 if (NFCTagReaderSession.readingAvailable) {
101 detectionRunning = scheduleSession(accessMethod);
102 if (detectionRunning)
103 activeAccessMethod = accessMethod;
104 return detectionRunning;
108 if (NFCNDEFReaderSession.readingAvailable) {
109 detectionRunning = scheduleSession(accessMethod);
110 if (detectionRunning)
111 activeAccessMethod = accessMethod;
112 return detectionRunning;
122 if (!detectionRunning)
125 isSessionScheduled =
false;
132 qCWarning(QT_IOS_NFC,
"Unknown access method, cannot stop target detection");
136 detectionRunning =
false;
143 isSessionScheduled =
true;
151 return startNdefSession();
157void QNearFieldManagerPrivateImpl::startSession()
159 if (@available(
iOS 13, *)) {
160 [delegate startSession];
164bool QNearFieldManagerPrivateImpl::startNdefSession()
170 __block
bool startSessionSucceded =
false;
171 dispatch_sync(
queue, ^{ startSessionSucceded = [ndefDelegate startSession]; });
172 return startSessionSucceded;
178void QNearFieldManagerPrivateImpl::stopSession(
const QString &
error)
184 if (@available(
iOS 13, *)) {
185 [delegate stopSession:
error];
189void QNearFieldManagerPrivateImpl::stopNdefSession(
const QString &
error)
196 dispatch_sync(
queue, ^{
197 [ndefDelegate stopSession:
error];
202void QNearFieldManagerPrivateImpl::clearTargets()
204 auto i = detectedTargets.
begin();
205 while (
i != detectedTargets.
end()) {
215 if (detectionRunning) {
217 qCWarning(QT_IOS_NFC,
"User information must be set prior before the targer detection started");
224 dispatch_sync(
queue, ^{
225 [ndefDelegate setAlertMessage:
message];
230void QNearFieldManagerPrivateImpl::onTagDiscovered(
void *
tag)
240 detectedTargets +=
target;
243 this, &QNearFieldManagerPrivateImpl::onTargetLost);
249 detectedTargets.removeOne(
target);
252 if (detectionRunning && detectedTargets.
isEmpty())
253 onDidInvalidateWithError(
true);
256void QNearFieldManagerPrivateImpl::onDidInvalidateWithError(
bool doRestart)
259 sessionTimer.
start();
261 if (detectionRunning && doRestart && scheduleSession(activeAccessMethod))
264 detectionRunning =
false;
268void QNearFieldManagerPrivateImpl::onSessionTimer()
270 if (isSessionScheduled && !scheduleSession(activeAccessMethod)) {
271 detectionRunning =
false;
DarwinBluetooth::LECBManagerNotifier * notifier
std::unique_ptr< QTimer > watchDog
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
iterator erase(const_iterator it)
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
void didInvalidateWithError(bool doRestart)
QNearFieldManagerPrivateImpl()
bool isSupported(QNearFieldTarget::AccessMethod accessMethod) const override
void tagDiscovered(void *tag)
bool startTargetDetection(QNearFieldTarget::AccessMethod accessMethod) override
void setUserInformation(const QString &message) override
~QNearFieldManagerPrivateImpl() override
void stopTargetDetection(const QString &errorMessage) override
void targetDetected(QNearFieldTarget *target)
void targetLost(QNearFieldTarget *target)
void targetDetectionStopped()
void targetLost(QNearFieldTargetPrivateImpl *target)
The QNearFieldTarget class provides an interface for communicating with a target device.
AccessMethod
This enum describes the access methods a near field target supports.
void tagDetected(void *tag)
void invalidateWithError(bool restart)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
void setSingleShot(bool singleShot)
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
void setInterval(int msec)
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
Combined button and popup list for selecting options.
AudioChannelLayoutTag tag
DBusConnection const char DBusError * error
QT_BEGIN_NAMESPACE dispatch_queue_t qt_Nfc_Queue()
#define qCWarning(category,...)
GLuint GLsizei const GLchar * message
#define QT_MANGLE_NAMESPACE(name)
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)