首页 > 解决方案 > 通过 ionic 在 NFC 标签上写入 WiFi ssid 和密码

问题描述

我想做的是在 NFC 标签上写一个 wifi 网络,你必须将你的手机撞到标签上,然后你的手机连接到它。我通过 NFC 工具对此进行了测试,并且成功了。

我正在尝试更改我的 NFC nDef 写入功能的类型,但似乎在文档或在线中找不到它。

打字稿服务 NFC:

 WriteNFC(text: string) {
    this.writeNfcAlert(text).then(alert => alert.present());
    console.log(text);
    let message = [this.ndef.textRecord(text)];
    let listener = this.nfc
      .addNdefListener(
        listener => {
          this.ndefWrite = true;
        },
        err => {
          this.ndefWrite = false;
        }
      )
      .subscribe(event => {
        if (this.ndefWrite) {
          this.alertController.dismiss();
          this.nfc
            .write(message)
            .then(() => {
              this.alertController.dismiss();
              this.presentToast("Successfuly written to tag.");
            })
            .catch(() => {
              this.WriteNFC(text);
              this.presentToast("Not able to write to tag, try again.");
            });
        }
        this.alertController.dismiss();
        this.ndefWrite = false;
      });
  }

  WriteWiFiNFC(){
    this.writeNfcAlert("new WiFi connection").then(alert => alert.present());
    let message = [this.ndef.TNF_EXTERNAL_TYPE]
  }

我可能对 NFC 还不够熟悉。但是我正在尝试找到一种解决方案来更改我的 NFC 标签的类型,以便当我扫描 NFC 标签以查找联系人时,它也会像使用 NFC 工具一样检测到它。

我在这里先向您的帮助表示感谢。

更新:
我发现你必须使用 application/vnd.wfa.wsc

    let message = [this.ndef.record(this.ndef.TNF_MIME_MEDIA, "application/vnd.wfa.wsc", "", "Network Name: test Authentication Type:OPEN Encryption Type: NONE Pasword: kak")];

我仍在研究如何添加正确的有效负载,我将查看文档 https://android.googlesource.com/platform/packages/apps/Nfc/+/master/src/com/android/nfc /NfcWifiProtectedSetup.java

更新 2
发现您必须在 NFC 上写入一些特定变量才能让您的手机将其识别为网络。
- NetworkName
- AuthenticationType
- EncryptionType
- NetworkKey
- MacAddress

标签: ionic-frameworkionic4nfcionic-nativendef

解决方案


推荐阅读