New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-nfc-uid

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-nfc-uid - npm Package Compare versions

Comparing version 6.0.7 to 6.0.8

2

index.ios.d.ts

@@ -9,2 +9,3 @@ import { NDEFListenerOptions, NfcApi, NfcNdefData, NfcTagData, WriteTagOptions, WriteGuardBeforeCheckError, WriteGuardAfterCheckError } from './common';

private delegate;
private writeDelegate;
message: NFCNDEFMessage;

@@ -21,3 +22,4 @@ private static _available;

private createNFCNDEFReaderSessionDelegate;
private createNFCNDEFReaderSessionDelegateWrite;
private beginNFCNDEFReaderSession;
}

851

index.ios.js

@@ -1,4 +0,4 @@

var NFCNDEFReaderSessionDelegateImpl_1;
var NFCNDEFReaderSessionDelegateImpl_1, NFCNDEFReaderSessionDelegateWriteImpl_1;
import { Utils } from '@nativescript/core';
import { WriteGuardBeforeCheckError, WriteGuardAfterCheckError, } from './common';
import { NfcUriProtocols, WriteGuardBeforeCheckError, WriteGuardAfterCheckError, } from './common';
export { WriteGuardBeforeCheckError, WriteGuardAfterCheckError };

@@ -79,45 +79,39 @@ export class Nfc {

writeTag(options, writeGuardBeforeCheckCallback, writeGuardAfterCheckCallback) {
return new Promise((resolve, reject) => { alert("do nothing"); });
return new Promise((resolve, reject) => {
if (!Nfc._available()) {
reject();
return;
}
try {
this.message = NfcHelper.jsonToNdefRecords(options.textRecords);
const delegateCallback = (data) => {
Utils.executeOnMainThread(() => {
return resolve(data);
});
};
const delegateErrorCallback = (error) => {
Utils.executeOnMainThread(() => {
return reject(error);
});
};
const delegateWriteGuardBeforeCheckCallback = (data) => {
if (!writeGuardBeforeCheckCallback) {
return true;
}
return writeGuardBeforeCheckCallback(data);
};
const delegateWriteGuardAfterCheckCallback = (data) => {
if (!writeGuardAfterCheckCallback) {
return true;
}
return writeGuardAfterCheckCallback(data);
};
this.writeDelegate = this.createNFCNDEFReaderSessionDelegateWrite(options, delegateCallback, delegateErrorCallback, delegateWriteGuardBeforeCheckCallback, delegateWriteGuardAfterCheckCallback);
this.beginNFCNDEFReaderSession(this.writeDelegate, options);
}
catch (e) {
reject(e);
}
});
}
// if (!Nfc._available()) {
// reject();
// return;
// }
// try {
// this.message = NfcHelper.jsonToNdefRecords(options.textRecords);
// const delegateCallback = (data) => {
// Utils.executeOnMainThread(() => {
// return resolve(data);
// });
// };
// const delegateErrorCallback = (error) => {
// Utils.executeOnMainThread(() => {
// return reject(error);
// });
// };
// const delegateWriteGuardBeforeCheckCallback = (data: NfcNdefData) => {
// if (!writeGuardBeforeCheckCallback) {
// return true;
// }
// return writeGuardBeforeCheckCallback(data);
// };
// const delegateWriteGuardAfterCheckCallback = (data: NfcNdefData) => {
// if (!writeGuardAfterCheckCallback) {
// return true;
// }
// return writeGuardAfterCheckCallback(data);
// };
// this.writeDelegate = this.createNFCNDEFReaderSessionDelegateWrite(
// options,
// delegateCallback,
// delegateErrorCallback,
// delegateWriteGuardBeforeCheckCallback,
// delegateWriteGuardAfterCheckCallback
// );
// this.beginNFCNDEFReaderSession(this.writeDelegate, options);
// } catch (e) {
// reject(e);
// }
// });
// }
eraseTag() {

@@ -132,20 +126,6 @@ return new Promise((resolve, reject) => {

}
// private createNFCNDEFReaderSessionDelegateWrite(
// options?: WriteTagOptions,
// callback?: (data: any) => void,
// errorCallback?: (data: any) => void,
// writeGuardBeforeCheckCallback?: (data: NfcNdefData) => boolean,
// writeGuardAfterCheckCallback?: (data: NfcNdefData) => boolean
// ) {
// const delegate =
// NFCNDEFReaderSessionDelegateWriteImpl.createWithOwnerResultCallbackAndOptions(
// new WeakRef(this),
// callback,
// errorCallback,
// writeGuardBeforeCheckCallback,
// writeGuardAfterCheckCallback,
// options
// );
// return delegate;
// }
createNFCNDEFReaderSessionDelegateWrite(options, callback, errorCallback, writeGuardBeforeCheckCallback, writeGuardAfterCheckCallback) {
const delegate = NFCNDEFReaderSessionDelegateWriteImpl.createWithOwnerResultCallbackAndOptions(new WeakRef(this), callback, errorCallback, writeGuardBeforeCheckCallback, writeGuardAfterCheckCallback, options);
return delegate;
}
beginNFCNDEFReaderSession(delegate, options) {

@@ -162,10 +142,9 @@ console.log('Create and begin NFCNDEFReaderSession');

let NFCNDEFReaderSessionDelegateImpl = NFCNDEFReaderSessionDelegateImpl_1 = class NFCNDEFReaderSessionDelegateImpl extends NSObject {
// public static new(): NFCNDEFReaderSessionDelegateImpl {
// try {
// NFCNDEFReaderSessionDelegateImpl.ObjCProtocols.push(
// NFCNDEFReaderSessionDelegate
// );
// } catch (ignore) {}
// return <NFCNDEFReaderSessionDelegateImpl>super.new();
// }
static new() {
try {
NFCNDEFReaderSessionDelegateImpl_1.ObjCProtocols.push(NFCNDEFReaderSessionDelegate);
}
catch (ignore) { }
return super.new();
}
static createWithOwnerResultCallbackAndOptions(owner, callback, options) {

@@ -185,7 +164,7 @@ const delegate = (NFCNDEFReaderSessionDelegateImpl_1.new());

alert("message:" + JSON.stringify(firstMessage));
// if (this.options && this.options.stopAfterFirstRead) {
// setTimeout(() => this._owner.get().invalidateSession());
// }
// // execute on the main thread with this trick
// this.resultCallback(NfcHelper.ndefToJson(firstMessage));
if (this.options && this.options.stopAfterFirstRead) {
setTimeout(() => this._owner.get().invalidateSession());
}
// execute on the main thread with this trick
this.resultCallback(NfcHelper.ndefToJson(firstMessage));
}

@@ -202,405 +181,321 @@ // // Called when the reader session becomes invalid due to the specified error

], NFCNDEFReaderSessionDelegateImpl);
// @NativeClass()
// class NFCNDEFReaderSessionDelegateWriteImpl
// extends NSObject
// implements NFCNDEFReaderSessionDelegate
// {
// public static ObjCProtocols = [];
// private _owner: WeakRef<Nfc>;
// private resultCallback: (message: any) => void;
// private errorCallback: (error: any) => void;
// private writeGuardBeforeCheckCallback: (data: NfcNdefData) => boolean;
// private writeGuardAfterCheckCallback: (data: NfcNdefData) => boolean;
// private writeGuardAfterCheck: boolean;
// private options?: WriteTagOptions;
// public static new(): NFCNDEFReaderSessionDelegateWriteImpl {
// try {
// NFCNDEFReaderSessionDelegateWriteImpl.ObjCProtocols.push(
// NFCNDEFReaderSessionDelegate
// );
// } catch (ignore) {}
// return <NFCNDEFReaderSessionDelegateWriteImpl>super.new();
// }
// public static createWithOwnerResultCallbackAndOptions(
// owner: WeakRef<Nfc>,
// callback: (message: any) => void,
// errorCallback: (error: any) => void,
// writeGuardBeforeCheckCallback: (data: NfcNdefData) => boolean,
// writeGuardAfterCheckCallback: (data: NfcNdefData) => boolean,
// options?: WriteTagOptions
// ): NFCNDEFReaderSessionDelegateWriteImpl {
// let delegate = <NFCNDEFReaderSessionDelegateWriteImpl>(
// NFCNDEFReaderSessionDelegateWriteImpl.new()
// );
// delegate._owner = owner;
// delegate.options = options;
// delegate.resultCallback = callback;
// delegate.errorCallback = errorCallback;
// delegate.writeGuardBeforeCheckCallback = writeGuardBeforeCheckCallback;
// delegate.writeGuardAfterCheckCallback = writeGuardAfterCheckCallback;
// delegate.writeGuardAfterCheck = false;
// return delegate;
// }
// readerSessionDidBecomeActive(session: NFCNDEFReaderSession): void {
// // ignore, but by implementing this function we suppress a log about it not being implemented ;)
// }
// // Called when the reader session finds a new tag
// readerSessionDidDetectNDEFs(
// session: NFCNDEFReaderSession,
// messages: NSArray<NFCNDEFMessage>
// ): void {}
// readerSessionDidDetectTags(
// session: NFCNDEFReaderSession,
// tags: NSArray<NFCNDEFTag> | NFCNDEFTag[]
// ): void {
// const prototype = NFCNDEFTag.prototype;
// const tag = (<NSArray<NFCNDEFTag>>tags).firstObject;
// session.connectToTagCompletionHandler(tag, (error: NSError) => {
// console.log('connectToTagCompletionHandler');
// if (error) {
// console.log(error);
// session.invalidateSessionWithErrorMessage('Unable to connect to tag.');
// this.errorCallback(error);
// return;
// }
// if (this.writeGuardAfterCheck) {
// // Read back the data
// prototype.readNDEFWithCompletionHandler.call(
// tag,
// (message: NFCNDEFMessage, error: NSError) => {
// console.log("readNDEFWithCompletionHandler");
// if (error) {
// console.log(error);
// session.invalidateSessionWithErrorMessage(
// "Error reading NDEF message from tag."
// );
// this.errorCallback(error);
// return;
// }
// const data = NfcHelper.ndefToJson(message);
// console.log("Read After Write Message", JSON.stringify(data));
// if (this.writeGuardAfterCheckCallback(data)) {
// if (this.options.endMessage) {
// session.alertMessage = this.options.endMessage;
// }
// this.resultCallback(data);
// session.invalidateSession();
// return;
// } else {
// const errorMessage =
// this.options.writeGuardAfterCheckErrorMessage || "";
// session.invalidateSessionWithErrorMessage(errorMessage);
// this.errorCallback(
// new WriteGuardAfterCheckError(errorMessage, data)
// );
// return;
// }
// }
// );
// return;
// }
// try {
// prototype.queryNDEFStatusWithCompletionHandler.call(
// tag,
// (status: NFCNDEFStatus, number: number, error: NSError) => {
// console.log('queryNDEFStatusWithCompletionHandler');
// if (error) {
// console.log(error);
// session.invalidateSessionWithErrorMessage(
// 'Unable to query the NDEF status of tag.'
// );
// this.errorCallback(error);
// return;
// }
// switch (status) {
// case NFCNDEFStatus.NotSupported:
// session.invalidateSessionWithErrorMessage(
// 'Tag is not NDEF compliant.'
// );
// break;
// case NFCNDEFStatus.ReadOnly:
// session.invalidateSessionWithErrorMessage('Tag is read only.');
// break;
// case NFCNDEFStatus.ReadWrite:
// prototype.readNDEFWithCompletionHandler.call(
// tag,
// (message: NFCNDEFMessage, error: NSError) => {
// console.log("readNDEFWithCompletionHandler");
// if (error) {
// console.log(error);
// session.invalidateSessionWithErrorMessage(
// "Error reading NDEF message from tag."
// );
// this.errorCallback(error);
// return;
// }
// const data = NfcHelper.ndefToJson(message);
// console.log("First Read Message", JSON.stringify(data));
// if (!this.writeGuardBeforeCheckCallback(data)) {
// const errorMessage =
// this.options.writeGuardBeforeCheckErrorMessage || "";
// session.invalidateSessionWithErrorMessage(errorMessage);
// this.errorCallback(
// new WriteGuardBeforeCheckError(errorMessage, data)
// );
// return;
// }
// session.connectToTagCompletionHandler(
// tag,
// (error: NSError) => {
// console.log("connectToTagCompletionHandler");
// if (error) {
// console.log(error);
// session.invalidateSessionWithErrorMessage(
// "Unable to connect to tag."
// );
// this.errorCallback(error);
// return;
// }
// // Start writing
// const ndefMessage = this._owner.get().message;
// prototype.writeNDEFCompletionHandler.call(
// tag,
// ndefMessage,
// (error: NSError) => {
// console.log("writeNDEFCompletionHandler");
// if (error) {
// console.log(error);
// session.invalidateSessionWithErrorMessage(
// "Write NDEF message failed."
// );
// this.errorCallback(error);
// } else {
// // This is not fully implemented yet
// if (
// ndefMessage.records[0].typeNameFormat ==
// NFCTypeNameFormat.Empty
// ) {
// session.alertMessage =
// "Erased data from NFC tag.";
// } else {
// this.writeGuardAfterCheck = true;
// if (this.options.writeGuardAfterCheckMessage) {
// session.alertMessage =
// this.options.writeGuardAfterCheckMessage;
// }
// Utils.executeOnMainThread(() =>
// setTimeout(
// () => session.restartPolling(),
// this.options.writeGuardAfterCheckDelay
// )
// );
// return;
// }
// session.invalidateSession();
// return;
// }
// }
// );
// }
// );
// }
// );
// break;
// default:
// session.invalidateSessionWithErrorMessage(
// 'Unknown NDEF tag status.'
// );
// break;
// }
// }
// );
// } catch (e) {
// console.log(e);
// session.alertMessage = `Write NDEF message failed: ${e}`;
// }
// });
// }
// // Called when the reader session becomes invalid due to the specified error
// readerSessionDidInvalidateWithError(
// session: any /* NFCNDEFReaderSession */,
// error: NSError
// ): void {
// this._owner.get().invalidateSession();
// }
// }
// class NfcHelper {
// // For write
// public static ndefEmptyMessage(): NFCNDEFMessage {
// let type: NSData = NfcHelper.uint8ArrayToNSData([]);
// let id: NSData = NfcHelper.uint8ArrayToNSData([]);
// const payload: NSData = NfcHelper.uint8ArrayToNSData([]);
// let record = NFCNDEFPayload.alloc().initWithFormatTypeIdentifierPayload(
// NFCTypeNameFormat.Empty,
// type,
// id,
// payload
// );
// let records: NSMutableArray<NFCNDEFPayload> = NSMutableArray.new();
// records.addObject(record);
// return NFCNDEFMessage.alloc().initWithNDEFRecords(records);
// }
// public static jsonToNdefRecords(textRecords: TextRecord[]): NFCNDEFMessage {
// let records: NSMutableArray<NFCNDEFPayload> = NSMutableArray.new();
// if (textRecords !== null) {
// textRecords.forEach((textRecord) => {
// let type: NSData = NfcHelper.uint8ArrayToNSData([0x54]);
// let ids = [];
// if (textRecord.id) {
// for (let j = 0; j < textRecord.id.length; j++) {
// ids.push(textRecord.id[j]);
// }
// }
// let id: NSData = NfcHelper.uint8ArrayToNSData(ids);
// let langCode = textRecord.languageCode || 'en';
// let encoded = NfcHelper.stringToBytes(langCode + textRecord.text);
// encoded.unshift(langCode.length); // STX (start of text)
// let payloads = [];
// for (let n = 0; n < encoded.length; n++) {
// payloads[n] = encoded[n];
// }
// const payload: NSData = NfcHelper.uint8ArrayToNSData(payloads);
// let record = NFCNDEFPayload.alloc().initWithFormatTypeIdentifierPayload(
// NFCTypeNameFormat.NFCWellKnown,
// type,
// id,
// payload
// );
// records.addObject(record);
// });
// }
// // TODO: implement for URI records
// return NFCNDEFMessage.alloc().initWithNDEFRecords(records);
// }
// private static uint8ArrayToNSData(array): NSData {
// let data: NSMutableData = NSMutableData.alloc().initWithCapacity(
// array.count
// );
// for (let item of array) {
// data.appendBytesLength(
// new interop.Reference(interop.types.uint8, item),
// 1
// );
// }
// return data;
// }
// private static stringToBytes(input: string) {
// let bytes = [];
// for (let n = 0; n < input.length; n++) {
// let c = input.charCodeAt(n);
// if (c < 128) {
// bytes[bytes.length] = c;
// } else if (c > 127 && c < 2048) {
// bytes[bytes.length] = (c >> 6) | 192;
// bytes[bytes.length] = (c & 63) | 128;
// } else {
// bytes[bytes.length] = (c >> 12) | 224;
// bytes[bytes.length] = ((c >> 6) & 63) | 128;
// bytes[bytes.length] = (c & 63) | 128;
// }
// }
// return bytes;
// }
// // For write end
// public static ndefToJson(message: NFCNDEFMessage): NfcNdefData {
// if (message === null) {
// return null;
// }
// return {
// message: this.messageToJSON(message),
// };
// }
// public static messageToJSON(message: NFCNDEFMessage): Array<NfcNdefRecord> {
// const result = [];
// for (let i = 0; i < message.records.count; i++) {
// result.push(this.recordToJSON(message.records.objectAtIndex(i)));
// }
// return result;
// }
// private static recordToJSON(record: NFCNDEFPayload): NfcNdefRecord {
// let payloadAsHexArray = this.nsdataToHexArray(record.payload);
// let payloadAsString = this.nsdataToASCIIString(record.payload);
// let payloadAsStringWithPrefix = payloadAsString;
// const recordType = this.nsdataToHexArray(record.type);
// const decimalType = this.hexToDec(recordType[0]);
// if (decimalType === 84) {
// let languageCodeLength: number = +payloadAsHexArray[0];
// payloadAsString = payloadAsStringWithPrefix.substring(
// languageCodeLength + 1
// );
// } else if (decimalType === 85) {
// let prefix = NfcUriProtocols[payloadAsHexArray[0]];
// if (!prefix) {
// prefix = '';
// }
// payloadAsString = prefix + payloadAsString.slice(1);
// }
// return {
// tnf: record.typeNameFormat, // "typeNameFormat" (1 = well known) - see https://developer.apple.com/documentation/corenfc/nfctypenameformat?changes=latest_major&language=objc
// type: decimalType,
// id: this.hexToDecArray(this.nsdataToHexArray(record.identifier)),
// payload: this.hexToDecArray(payloadAsHexArray),
// payloadAsHexString: this.nsdataToHexString(record.payload),
// payloadAsStringWithPrefix: payloadAsStringWithPrefix,
// payloadAsString: payloadAsString,
// };
// }
// private static hexToDec(hex) {
// if (hex === undefined) {
// return undefined;
// }
// let result = 0,
// digitValue;
// hex = hex.toLowerCase();
// for (let i = 0; i < hex.length; i++) {
// digitValue = '0123456789abcdefgh'.indexOf(hex[i]);
// result = result * 16 + digitValue;
// }
// return result;
// }
// private static buf2hexString(buffer) {
// // buffer is an ArrayBuffer
// return Array.prototype.map
// .call(new Uint8Array(buffer), (x) => ('00' + x.toString(16)).slice(-2))
// .join('');
// }
// private static buf2hexArray(buffer) {
// // buffer is an ArrayBuffer
// return Array.prototype.map.call(new Uint8Array(buffer), (x) =>
// ('00' + x.toString(16)).slice(-2)
// );
// }
// private static hex2a(hexx) {
// const hex = hexx.toString(); // force conversion
// let str = '';
// for (let i = 0; i < hex.length; i += 2)
// str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
// return str;
// }
// private static nsdataToHexString(data): string {
// let b = interop.bufferFromData(data);
// return this.buf2hexString(b);
// }
// private static nsdataToHexArray(data): Array<string> {
// let b = interop.bufferFromData(data);
// return this.buf2hexArray(b);
// }
// private static nsdataToASCIIString(data): string {
// return this.hex2a(this.nsdataToHexString(data));
// }
// private static hexToDecArray(hexArray): any {
// let resultArray = [];
// for (let i = 0; i < hexArray.length; i++) {
// let result = 0,
// digitValue;
// const hex = hexArray[i].toLowerCase();
// for (let j = 0; j < hex.length; j++) {
// digitValue = '0123456789abcdefgh'.indexOf(hex[j]);
// result = result * 16 + digitValue;
// }
// resultArray.push(result);
// }
// return JSON.stringify(resultArray);
// }
// }
let NFCNDEFReaderSessionDelegateWriteImpl = NFCNDEFReaderSessionDelegateWriteImpl_1 = class NFCNDEFReaderSessionDelegateWriteImpl extends NSObject {
static new() {
try {
NFCNDEFReaderSessionDelegateWriteImpl_1.ObjCProtocols.push(NFCNDEFReaderSessionDelegate);
}
catch (ignore) { }
return super.new();
}
static createWithOwnerResultCallbackAndOptions(owner, callback, errorCallback, writeGuardBeforeCheckCallback, writeGuardAfterCheckCallback, options) {
let delegate = (NFCNDEFReaderSessionDelegateWriteImpl_1.new());
delegate._owner = owner;
delegate.options = options;
delegate.resultCallback = callback;
delegate.errorCallback = errorCallback;
delegate.writeGuardBeforeCheckCallback = writeGuardBeforeCheckCallback;
delegate.writeGuardAfterCheckCallback = writeGuardAfterCheckCallback;
delegate.writeGuardAfterCheck = false;
return delegate;
}
readerSessionDidBecomeActive(session) {
// ignore, but by implementing this function we suppress a log about it not being implemented ;)
}
// Called when the reader session finds a new tag
readerSessionDidDetectNDEFs(session, messages) { }
readerSessionDidDetectTags(session, tags) {
const prototype = NFCNDEFTag.prototype;
const tag = tags.firstObject;
session.connectToTagCompletionHandler(tag, (error) => {
console.log('connectToTagCompletionHandler');
if (error) {
console.log(error);
session.invalidateSessionWithErrorMessage('Unable to connect to tag.');
this.errorCallback(error);
return;
}
if (this.writeGuardAfterCheck) {
// Read back the data
prototype.readNDEFWithCompletionHandler.call(tag, (message, error) => {
console.log("readNDEFWithCompletionHandler");
if (error) {
console.log(error);
session.invalidateSessionWithErrorMessage("Error reading NDEF message from tag.");
this.errorCallback(error);
return;
}
const data = NfcHelper.ndefToJson(message);
console.log("Read After Write Message", JSON.stringify(data));
if (this.writeGuardAfterCheckCallback(data)) {
if (this.options.endMessage) {
session.alertMessage = this.options.endMessage;
}
this.resultCallback(data);
session.invalidateSession();
return;
}
else {
const errorMessage = this.options.writeGuardAfterCheckErrorMessage || "";
session.invalidateSessionWithErrorMessage(errorMessage);
this.errorCallback(new WriteGuardAfterCheckError(errorMessage, data));
return;
}
});
return;
}
try {
prototype.queryNDEFStatusWithCompletionHandler.call(tag, (status, number, error) => {
console.log('queryNDEFStatusWithCompletionHandler');
if (error) {
console.log(error);
session.invalidateSessionWithErrorMessage('Unable to query the NDEF status of tag.');
this.errorCallback(error);
return;
}
switch (status) {
case 1 /* NFCNDEFStatus.NotSupported */:
session.invalidateSessionWithErrorMessage('Tag is not NDEF compliant.');
break;
case 3 /* NFCNDEFStatus.ReadOnly */:
session.invalidateSessionWithErrorMessage('Tag is read only.');
break;
case 2 /* NFCNDEFStatus.ReadWrite */:
prototype.readNDEFWithCompletionHandler.call(tag, (message, error) => {
console.log("readNDEFWithCompletionHandler");
if (error) {
console.log(error);
session.invalidateSessionWithErrorMessage("Error reading NDEF message from tag.");
this.errorCallback(error);
return;
}
const data = NfcHelper.ndefToJson(message);
console.log("First Read Message", JSON.stringify(data));
if (!this.writeGuardBeforeCheckCallback(data)) {
const errorMessage = this.options.writeGuardBeforeCheckErrorMessage || "";
session.invalidateSessionWithErrorMessage(errorMessage);
this.errorCallback(new WriteGuardBeforeCheckError(errorMessage, data));
return;
}
session.connectToTagCompletionHandler(tag, (error) => {
console.log("connectToTagCompletionHandler");
if (error) {
console.log(error);
session.invalidateSessionWithErrorMessage("Unable to connect to tag.");
this.errorCallback(error);
return;
}
// Start writing
const ndefMessage = this._owner.get().message;
prototype.writeNDEFCompletionHandler.call(tag, ndefMessage, (error) => {
console.log("writeNDEFCompletionHandler");
if (error) {
console.log(error);
session.invalidateSessionWithErrorMessage("Write NDEF message failed.");
this.errorCallback(error);
}
else {
// This is not fully implemented yet
if (ndefMessage.records[0].typeNameFormat ==
0 /* NFCTypeNameFormat.Empty */) {
session.alertMessage =
"Erased data from NFC tag.";
}
else {
this.writeGuardAfterCheck = true;
if (this.options.writeGuardAfterCheckMessage) {
session.alertMessage =
this.options.writeGuardAfterCheckMessage;
}
Utils.executeOnMainThread(() => setTimeout(() => session.restartPolling(), this.options.writeGuardAfterCheckDelay));
return;
}
session.invalidateSession();
return;
}
});
});
});
break;
default:
session.invalidateSessionWithErrorMessage('Unknown NDEF tag status.');
break;
}
});
}
catch (e) {
console.log(e);
session.alertMessage = `Write NDEF message failed: ${e}`;
}
});
}
// Called when the reader session becomes invalid due to the specified error
readerSessionDidInvalidateWithError(session /* NFCNDEFReaderSession */, error) {
this._owner.get().invalidateSession();
}
};
NFCNDEFReaderSessionDelegateWriteImpl.ObjCProtocols = [];
NFCNDEFReaderSessionDelegateWriteImpl = NFCNDEFReaderSessionDelegateWriteImpl_1 = __decorate([
NativeClass()
], NFCNDEFReaderSessionDelegateWriteImpl);
class NfcHelper {
// For write
static ndefEmptyMessage() {
let type = NfcHelper.uint8ArrayToNSData([]);
let id = NfcHelper.uint8ArrayToNSData([]);
const payload = NfcHelper.uint8ArrayToNSData([]);
let record = NFCNDEFPayload.alloc().initWithFormatTypeIdentifierPayload(0 /* NFCTypeNameFormat.Empty */, type, id, payload);
let records = NSMutableArray.new();
records.addObject(record);
return NFCNDEFMessage.alloc().initWithNDEFRecords(records);
}
static jsonToNdefRecords(textRecords) {
let records = NSMutableArray.new();
if (textRecords !== null) {
textRecords.forEach((textRecord) => {
let type = NfcHelper.uint8ArrayToNSData([0x54]);
let ids = [];
if (textRecord.id) {
for (let j = 0; j < textRecord.id.length; j++) {
ids.push(textRecord.id[j]);
}
}
let id = NfcHelper.uint8ArrayToNSData(ids);
let langCode = textRecord.languageCode || 'en';
let encoded = NfcHelper.stringToBytes(langCode + textRecord.text);
encoded.unshift(langCode.length); // STX (start of text)
let payloads = [];
for (let n = 0; n < encoded.length; n++) {
payloads[n] = encoded[n];
}
const payload = NfcHelper.uint8ArrayToNSData(payloads);
let record = NFCNDEFPayload.alloc().initWithFormatTypeIdentifierPayload(1 /* NFCTypeNameFormat.NFCWellKnown */, type, id, payload);
records.addObject(record);
});
}
// TODO: implement for URI records
return NFCNDEFMessage.alloc().initWithNDEFRecords(records);
}
static uint8ArrayToNSData(array) {
let data = NSMutableData.alloc().initWithCapacity(array.count);
for (let item of array) {
data.appendBytesLength(new interop.Reference(interop.types.uint8, item), 1);
}
return data;
}
static stringToBytes(input) {
let bytes = [];
for (let n = 0; n < input.length; n++) {
let c = input.charCodeAt(n);
if (c < 128) {
bytes[bytes.length] = c;
}
else if (c > 127 && c < 2048) {
bytes[bytes.length] = (c >> 6) | 192;
bytes[bytes.length] = (c & 63) | 128;
}
else {
bytes[bytes.length] = (c >> 12) | 224;
bytes[bytes.length] = ((c >> 6) & 63) | 128;
bytes[bytes.length] = (c & 63) | 128;
}
}
return bytes;
}
// For write end
static ndefToJson(message) {
if (message === null) {
return null;
}
return {
message: this.messageToJSON(message),
};
}
static messageToJSON(message) {
const result = [];
for (let i = 0; i < message.records.count; i++) {
result.push(this.recordToJSON(message.records.objectAtIndex(i)));
}
return result;
}
static recordToJSON(record) {
let payloadAsHexArray = this.nsdataToHexArray(record.payload);
let payloadAsString = this.nsdataToASCIIString(record.payload);
let payloadAsStringWithPrefix = payloadAsString;
const recordType = this.nsdataToHexArray(record.type);
const decimalType = this.hexToDec(recordType[0]);
if (decimalType === 84) {
let languageCodeLength = +payloadAsHexArray[0];
payloadAsString = payloadAsStringWithPrefix.substring(languageCodeLength + 1);
}
else if (decimalType === 85) {
let prefix = NfcUriProtocols[payloadAsHexArray[0]];
if (!prefix) {
prefix = '';
}
payloadAsString = prefix + payloadAsString.slice(1);
}
return {
tnf: record.typeNameFormat,
type: decimalType,
id: this.hexToDecArray(this.nsdataToHexArray(record.identifier)),
payload: this.hexToDecArray(payloadAsHexArray),
payloadAsHexString: this.nsdataToHexString(record.payload),
payloadAsStringWithPrefix: payloadAsStringWithPrefix,
payloadAsString: payloadAsString,
};
}
static hexToDec(hex) {
if (hex === undefined) {
return undefined;
}
let result = 0, digitValue;
hex = hex.toLowerCase();
for (let i = 0; i < hex.length; i++) {
digitValue = '0123456789abcdefgh'.indexOf(hex[i]);
result = result * 16 + digitValue;
}
return result;
}
static buf2hexString(buffer) {
// buffer is an ArrayBuffer
return Array.prototype.map
.call(new Uint8Array(buffer), (x) => ('00' + x.toString(16)).slice(-2))
.join('');
}
static buf2hexArray(buffer) {
// buffer is an ArrayBuffer
return Array.prototype.map.call(new Uint8Array(buffer), (x) => ('00' + x.toString(16)).slice(-2));
}
static hex2a(hexx) {
const hex = hexx.toString(); // force conversion
let str = '';
for (let i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
static nsdataToHexString(data) {
let b = interop.bufferFromData(data);
return this.buf2hexString(b);
}
static nsdataToHexArray(data) {
let b = interop.bufferFromData(data);
return this.buf2hexArray(b);
}
static nsdataToASCIIString(data) {
return this.hex2a(this.nsdataToHexString(data));
}
static hexToDecArray(hexArray) {
let resultArray = [];
for (let i = 0; i < hexArray.length; i++) {
let result = 0, digitValue;
const hex = hexArray[i].toLowerCase();
for (let j = 0; j < hex.length; j++) {
digitValue = '0123456789abcdefgh'.indexOf(hex[j]);
result = result * 16 + digitValue;
}
resultArray.push(result);
}
return JSON.stringify(resultArray);
}
}
//# sourceMappingURL=index.ios.js.map
{
"name": "nativescript-nfc-uid",
"version": "6.0.7",
"version": "6.0.8",
"description": "Add a plugin description",

@@ -5,0 +5,0 @@ "main": "index",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc