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;
146 isSessionScheduled =
false;
152 return startNdefSession();
158void QNearFieldManagerPrivateImpl::startSession()
160 if (@available(
iOS 13, *)) {
161 [delegate startSession];
165bool QNearFieldManagerPrivateImpl::startNdefSession()
171 __block
bool startSessionSucceded =
false;
172 dispatch_sync(
queue, ^{ startSessionSucceded = [ndefDelegate startSession]; });
173 return startSessionSucceded;
179void QNearFieldManagerPrivateImpl::stopSession(
const QString &
error)
185 if (@available(
iOS 13, *)) {
186 [delegate stopSession:
error];
190void QNearFieldManagerPrivateImpl::stopNdefSession(
const QString &
error)
197 dispatch_sync(
queue, ^{
198 [ndefDelegate stopSession:
error];
203void QNearFieldManagerPrivateImpl::clearTargets()
205 auto i = detectedTargets.
begin();
206 while (
i != detectedTargets.
end()) {
218 if (detectionRunning) {
221 "User information must be set prior before the target detection started");
226 dispatch_sync(
queue, ^{
227 [ndefDelegate setAlertMessage:
message];
232void QNearFieldManagerPrivateImpl::onTagDiscovered(
void *
tag)
242 detectedTargets +=
target;
245 this, &QNearFieldManagerPrivateImpl::onTargetLost);
251 detectedTargets.removeOne(
target);
254 if (detectionRunning && detectedTargets.
isEmpty())
255 onDidInvalidateWithError(
true);
258void QNearFieldManagerPrivateImpl::onDidInvalidateWithError(
bool doRestart)
261 sessionTimer.
start();
263 if (detectionRunning && doRestart && scheduleSession(activeAccessMethod))
266 detectionRunning =
false;
270void QNearFieldManagerPrivateImpl::onSessionTimer()
272 if (isSessionScheduled && !scheduleSession(activeAccessMethod)) {
273 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)