-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback not executed on iOS 14 and NS 8 #70
Comments
I've fixed by using So I've changed these lines (in Nfc.prototype.setOnNdefDiscoveredListener )
with
Note that you need first to import Utils from nativescript core. |
@luffa99 Are you able to post exactly how you did this? Was it directly in node_modules or did you pull the files out. |
It looks like a PR was opened to fix this but was eventually closed: #71 I'm using diff --git a/node_modules/nativescript-nfc/nfc.ios.js b/node_modules/nativescript-nfc/nfc.ios.js
index c55b377..c300242 100644
--- a/node_modules/nativescript-nfc/nfc.ios.js
+++ b/node_modules/nativescript-nfc/nfc.ios.js
@@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Nfc = void 0;
+var core_1 = require("@nativescript/core");
var nfc_common_1 = require("./nfc.common");
var Nfc = /** @class */ (function () {
function Nfc() {
@@ -53,8 +54,9 @@ var Nfc = /** @class */ (function () {
JSON.stringify(data));
}
else {
+ core_1.Utils.executeOnMainThread(() => callback(data))
// execute on the main thread with this trick, so UI updates are not broken
- Promise.resolve().then(function () { return callback(data); });
+ // Promise.resolve().then(function () { return callback(data); });
}
}, options);
_this.session = NFCNDEFReaderSession.alloc().initWithDelegateQueueInvalidateAfterFirstRead(_this.delegate, null, options && options.stopAfterFirstRead);
@@ -125,7 +127,7 @@ var NFCNDEFReaderSessionDelegateImpl = /** @class */ (function (_super) {
// execute on the main thread with this trick
this.resultCallback(NFCNDEFReaderSessionDelegateImpl.ndefToJson(firstMessage));
};
- NFCNDEFReaderSessionDelegateImpl.prototype.readerSessionDidDetectTags = function (session, tags) {
+ // NFCNDEFReaderSessionDelegateImpl.prototype.readerSessionDidDetectTags = function (session, tags) {
/*
// TODO prolly remember the tags for when the app wants to write to it (also: check Android impl for possibly sth similar)
const nfcNdefTag = tags[0];
@@ -146,7 +148,7 @@ var NFCNDEFReaderSessionDelegateImpl = /** @class */ (function (_super) {
});
}
*/
- };
+ // };
// Called when the reader session becomes invalid due to the specified error
NFCNDEFReaderSessionDelegateImpl.prototype.readerSessionDidInvalidateWithError = function (session /* NFCNDEFReaderSession */, error) {
this._owner.get().invalidateSession(); |
Problem: when a NDEF tag is read the callback function set with
nfc.setOnNdefDiscoveredListener
is not calledExpected behaviour: the callback function is called after a tag is read
Platform: not working with nativescript 8 on iOS 14 (not tested with other versions). On Android with nativescript 8 works fine.
I've tried to investigate deeper in the library and discovered the critical point: at line 57-58 of
nfc.ios.js
the callback function should be called. I've tested to print data here, and it works fine, but the callback is not called.Thank you
The text was updated successfully, but these errors were encountered: