Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qiostagreaderdelegate.mm
Go to the documentation of this file.
1
// Copyright (C) 2020 Governikus GmbH & Co. KG
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qiostagreaderdelegate_p.h"
5
6
#
include
"qnearfieldmanager_ios_p.h"
7
8
#
import
<
CoreNFC
/
NFCError
.
h
>
9
#
import
<
CoreNFC
/
NFCTag
.
h
>
10
11
QT_USE_NAMESPACE
12
13
@implementation QT_MANGLE_NAMESPACE(QIosTagReaderDelegate)
14
15
- (instancetype)initWithListener:(QNearFieldManagerPrivateImpl *)listener
16
{
17
self = [super init];
18
if
(self) {
19
self.listener = listener;
20
self.sessionStoppedByApplication =
false
;
21
self.message = nil;
22
self.session = nil;
23
}
24
25
return
self;
26
}
27
28
- (
void
)startSession
29
{
30
if
(self.session && !self.sessionStoppedByApplication) {
31
[self.session invalidateSession];
32
self.sessionStoppedByApplication =
true
;
33
}
34
35
if
(self.sessionStoppedByApplication) {
36
Q_EMIT self.listener->didInvalidateWithError(
true
);
37
return
;
38
}
39
40
self.session = [[[NFCTagReaderSession alloc] initWithPollingOption:NFCPollingISO14443 delegate:self queue:nil] autorelease];
41
if
(self.session) {
42
if
(self.message)
43
self.session.alertMessage = self.message;
44
[self.session beginSession];
45
}
else
{
46
Q_EMIT self.listener->didInvalidateWithError(
true
);
47
}
48
}
49
50
- (
void
)stopSession:(QString)message
51
{
52
if
(self.session && !self.sessionStoppedByApplication) {
53
if
(message.isNull())
54
[self.session invalidateSession];
55
else
56
[self.session invalidateSessionWithErrorMessage:message.toNSString()];
57
self.sessionStoppedByApplication =
true
;
58
}
59
}
60
61
- (
void
)alertMessage:(QString)message
62
{
63
if
(self.session && !self.sessionStoppedByApplication)
64
self.session.alertMessage = message.toNSString();
65
else
66
self.message = message.toNSString();
67
}
68
69
- (
void
)tagReaderSessionDidBecomeActive:(NFCTagReaderSession*)session
70
{
71
if
(session != self.session)
72
[session invalidateSession];
73
}
74
75
- (
void
)tagReaderSession:(NFCTagReaderSession*)session didInvalidateWithError:(NSError*)error
76
{
77
if
(session != self.session)
78
return
;
79
80
self.session = nil;
81
if
(self.sessionStoppedByApplication) {
82
self.sessionStoppedByApplication =
false
;
83
return
;
84
}
85
86
const
bool
doRestart =
87
!(error.code == NFCReaderError::NFCReaderSessionInvalidationErrorUserCanceled
88
|| error.code == NFCReaderError::NFCReaderErrorUnsupportedFeature);
89
Q_EMIT self.listener->didInvalidateWithError(doRestart);
90
}
91
92
- (
void
)tagReaderSession:(NFCTagReaderSession*)session didDetectTags:(NSArray<__kindof id<NFCTag>>*)tags
93
{
94
if
(session != self.session)
95
return
;
96
97
bool
foundTag =
false
;
98
for
(id<NFCTag> tag in tags) {
99
if
(tag.type == NFCTagTypeISO7816Compatible) {
100
foundTag =
true
;
101
[tag retain];
102
Q_EMIT self.listener->tagDiscovered(tag);
103
}
104
}
105
106
if
(!foundTag)
107
[session restartPolling];
108
}
109
110
@end
qtconnectivity
src
nfc
ios
qiostagreaderdelegate.mm
Generated on
for Qt by
1.18.0