Angular 如何在NFC标签上书写?(离子型)
我有一个调用test2函数的按钮 这是我的代码:Angular 如何在NFC标签上书写?(离子型),angular,typescript,ionic-framework,nfc,Angular,Typescript,Ionic Framework,Nfc,我有一个调用test2函数的按钮 这是我的代码: import { Component } from '@angular/core'; import { NFC, Ndef } from '@ionic-native/nfc/ngx'; @Component({ selector: 'app-tab3', templateUrl: 'tab3.page.html', styleUrls: ['tab3.page.scss'] }) export class Tab3Page {
import { Component } from '@angular/core';
import { NFC, Ndef } from '@ionic-native/nfc/ngx';
@Component({
selector: 'app-tab3',
templateUrl: 'tab3.page.html',
styleUrls: ['tab3.page.scss']
})
export class Tab3Page {
constructor( private nfc: NFC, private ndef: Ndef,) {
}
test2(){
this.nfc.addNdefListener(() => {
console.log('successfully attached ndef listener');
}, (err) => {
console.log('error attaching ndef listener', err);
}).subscribe(() => {
console.log("works");
let message = [this.ndef.textRecord("hello, world")];
this.nfc.share(message);
}, err => console.log(err));
}
}
但是,订阅不会在我将NFC标记传递给它时立即触发。addNdefListener被正确触发,有什么问题吗
我使用离子5.6和电容器,我也使用本机的NFC插件
你能帮我吗?请
nfc。共享
用于两台设备之间的点对点,这一点已在Android 10中删除,但您的问题标题为“在nfc标签上写入”,您需要使用nfc.write
因为设备到设备的NFC协议与设备到标签协议完全不同。我如你所说更改了它,但它不起作用,然而,我回去阅读了所有文档,我没有看到我所写的有任何错误,所以我决定创建一个新项目并重做代码,它起了作用,文件可能已损坏,但我已修复,感谢您的支持。我猜这是在Android上?问题是什么安卓版本?是的,安卓9.0