【发布时间】:2018-11-10 16:43:58
【问题描述】:
我目前正在尝试在我的原生科尔多瓦应用程序中实现一个简单的读/写功能,每次我尝试擦除或写入标签时,我都会收到以下错误:Tag capacity is 0 bytes, message is 4 bytes.
为了提供信息,我随身携带的标签是:https://www.amazon.ca/Robojax-chain-13-56Mhz-Arduino-Raspberry/dp/B079Q9RYL3/ref=sr_1_1?ie=UTF8&qid=1527781307&sr=8-1&keywords=nfc+tags+keychain
我订购了8Kbit存储容量的标签,所以不明白是什么原因导致写入失败。
我正在使用示例离子 NFC 项目来读写标签:https://ionicframework.com/docs/native/nfc/
这里有一小段测试代码尝试写入/读取
this.nfc.addNdefListener( () => {
console.log("Successfully attached NDEF listener");
}, (err: any) => {
console.log("error attaching ndef listener", err);
}).subscribe( (event) => {
console.log("received NDF message", event);
if (this.isWriting) {
this.nfc.erase().then( () => {
console.log("Sucessfully erased the tag");
const a = this.ndef.textRecord("Hello world", "en", "usertoken");
this.nfc.write([a]).then( () => {
console.log("We wrote to the tag");
}).catch( (err: any) => {
console.log("we could not write to the tag", err);
})
}, (err: any) => {
console.log("Problem while attempting to erase tag", err)
});
}
})
我的 UI 中有一个按钮将 this.isWriting 设置为 true,这样我们就不会误写。
任何帮助将不胜感激!
【问题讨论】:
-
目前用的是三星note 8
标签: javascript cordova ionic-framework phonegap-plugins nfc