English 中文(简体)
能否用 PhoneGap 来读取 nfc 标签 UID? 如何?
原标题:Is it possible to read nfc tag UID with PhoneGap? How?

我想读一个 /NFC tag s UID ,标签上没有任何 undef 消息或任何东西(空),只是 UID 而已。关于Android, 很容易做,但电话开发速度快得多,所以我想知道能否让它在Phonegap上工作,也许可以使用 rel=“noreverr” >phonegap-nfc 插件。

最佳回答

“http://github.com/chariotsolutions/phonegap-nfc>>phonagap-nfc插件 将允许您阅读 tags UID

nfc.addTag DiscoveredListener () 是好的,如果需要标签id。 至于 phonegap-nfc-0.4.0 ,如果有的话,标签id也包含在 NDEF 听众中。

您可以用 nfc.bytesToHexString(tag.id) 转换为显示的十六进制字符串

function ready() {

    function onNfc(nfcEvent) {

        var tag = nfcEvent.tag;
        var tagId = nfc.bytesToHexString(tag.id);
        alert(tagId);

    }

    function win() {
        console.log("Listening for NFC Tags");
    }

    function fail(error) {
        alert("Error adding NFC listener");
    }


    nfc.addTagDiscoveredListener(onNfc, win, fail);
}

function init() {
    document.addEventListener( deviceready , ready, false);
}
问题回答

答案在您的问题中 : 是的, 请使用 NFC 插件 。 添加一个调回到 nfc.addTag DiscoveredListener () 的任何标签的回调 ()

我尝试了使用 phonegap nfc 插件, 应用程序工作正常, 日志上没有错误, 每当我读到标签 UID 时, 我就会没有定义 。





相关问题
Javascript data store solution using PhoneGap

Does anyone have any experience of storing data in JavaScript across all mobile platforms using PhoneGap? My ideal solution would be to use something like SQLite, but unfortunately SQLite isn t ...

get image from iphone, using phonegap camera api

I m new to Xcode and iPhone apps. I want to select an image from iPhone (camera or library) and send to php via ajax. http://wiki.phonegap.com/iPhone:-Camera-API I m using the phonegap framework, ...

Getting Search Keyboard on iPhone using PhoneGap

I have created a search field on a mobile app i am creating via PhoneGap. I ve tried using with no luck. I also know that i could get around the visual aspect of the input field via CSS & ...

How can I detect a shake gesture in PhoneGap 0.8?

I m using PhoneGap 0.8 and I d like to detect a basic shake gesture. I ve found two relevant snippets: http://groups.google.com/group/phonegap/browse_thread/thread/25178468b8eb9e9f http://phonegap....

How do I fix PhoneGap build errors?

I am trying to build a PhoneGap-based iPhone application, but I keep getting the following two errors: ./build-phonegap.sh: line 6: ./configure: No such file or directory cp: lib/iphone/phonegap-min....