@@ -141,22 +141,31 @@ export default class FlutterNfcKitPlugin implements FlutterPlugin, MethodCallHan
141
141
} else if (call.method == "transceive") {
142
142
let tx: string = call.argument("data");
143
143
hilog.info(0x0000, "FlutterNfcKitPlugin", "transceive: tx=%{public}s", JSON.stringify(tx));
144
- this.tag!.connect();
145
- this.tag!.transmit(fromHexString(tx)).then((rx) => {
146
- hilog.info(0x0000, "FlutterNfcKitPlugin", "transceive: rx=%{public}s", JSON.stringify(rx));
147
- result.success(toHexString(rx));
148
- }).catch((err: BusinessError) => {
149
- hilog.info(0x0000, "FlutterNfcKitPlugin", "Failed to transceive: err=%{public}s", JSON.stringify(err));
150
- result.error("500", "Transceive failed", err);
151
- });
144
+ if (this.tag !== null) {
145
+ this.tag!.connect();
146
+ this.tag!.transmit(fromHexString(tx)).then((rx) => {
147
+ hilog.info(0x0000, "FlutterNfcKitPlugin", "transceive: rx=%{public}s", JSON.stringify(rx));
148
+ result.success(toHexString(rx));
149
+ }).catch((err: BusinessError) => {
150
+ hilog.info(0x0000, "FlutterNfcKitPlugin", "Failed to transceive: err=%{public}s", JSON.stringify(err));
151
+ result.error("500", "Transceive failed", err);
152
+ });
153
+ } else {
154
+ result.error("406", "No tag polled", null);
155
+ }
152
156
} else if (call.method == "finish") {
153
157
// turn off reader mode
154
158
tag.off("readerMode", elementName, (err: BusinessError, tagInfo: tag.TagInfo) => {});
159
+ this.tag = null;
155
160
result.success("");
156
161
} else if (call.method == "setIosAlertMessage") {
157
162
// do nothing, just for compatibility
158
163
result.success("");
164
+ } else if (call.method == "readNDEF") {
165
+ // TODO
166
+ result.success("[]");
159
167
} else {
168
+ hilog.info(0x0000, "FlutterNfcKitPlugin", "Not implemented method: %{public}s", call.method);
160
169
result.notImplemented();
161
170
}
162
171
} catch (e) {
0 commit comments