GithubHelp home page GithubHelp logo

Comments (14)

EddyVerbruggen avatar EddyVerbruggen commented on May 30, 2024 1

Oh cool!

from nativescript-nfc.

EddyVerbruggen avatar EddyVerbruggen commented on May 30, 2024 1

I've added code to do a little PoC of this feature, but in my tests (on line 165) nfcNdefTag.writeNDEFCompletionHandler is undefined.

Here's the (commented) code.. feel free to play with it:

readerSessionDidDetectTags(session: NFCNDEFReaderSession, tags: NSArray<NFCNDEFTag> | NFCNDEFTag[]): void {
/*
// TODO prolly remember the tags for when the app wants to write to it (also: check Android impl for possibly sth similar)
const nfcNdefTag = tags[0];
session.connectToTagCompletionHandler(nfcNdefTag, (error: NSError) => {
console.log(">> connected to tag, error: " + error);
});
// TODO either Text or URI
const payload: NFCNDEFPayload = NFCNDEFPayload.wellKnownTypeTextPayloadWithStringLocale("EddyIOS", NSLocale.currentLocale);
console.log(">> payload: " + payload);
const ndefMessage: NFCNDEFMessage = NFCNDEFMessage.alloc().initWithNDEFRecords([payload]);
console.log(">> ndefMessage: " + ndefMessage);
if (nfcNdefTag.writeNDEFCompletionHandler) {
nfcNdefTag.writeNDEFCompletionHandler(ndefMessage, (error: NSError) => {
console.log(">> writeNDEFCompletionHandler, error: " + error);
});
}
*/
}

from nativescript-nfc.

sashok1337 avatar sashok1337 commented on May 30, 2024 1

Maybe it's somehow connected to NativeScript/ios-jsc#1251 ? There is also native object transforms to JS without needed methods. I've tested app with latest version of ios-platform (that consist fix of that error) - nfcNdefTag.writeNDEFCompletionHandler still undefined :(

from nativescript-nfc.

gasparrobi avatar gasparrobi commented on May 30, 2024

I'm trying to use your snippet. While the readerSessionDidDetectTags is called, the tags input parameter is undefined. I'm not sure why. I've tried with both empty and non-empty tags

from nativescript-nfc.

joeelia avatar joeelia commented on May 30, 2024

Looking forward to this working

from nativescript-nfc.

demetrius-tech avatar demetrius-tech commented on May 30, 2024

Do you guys need any help? I need this feature and may be you've already made some progress or I can start working on this.

from nativescript-nfc.

joeelia avatar joeelia commented on May 30, 2024

No progress. iOS write to NFC still dosent work for me

from nativescript-nfc.

demetrius-tech avatar demetrius-tech commented on May 30, 2024

Check this out: https://github.com/chariotsolutions/phonegap-nfc

The problem is that beginSession() is used instead of scanNdef().

"On iOS, the user must start a NFC session to scan for a tag. This is different from Android which can constantly scan for NFC tags. The nfc.scanNdef and nfc.scanTag functions start a NFC scanning session. The NFC tag is returned to the caller via a Promise. If your existing code uses the deprecated nfc.beginSession, update it to use nfc.scanNdef."

They recently fixed this on phonegap-nfc: chariotsolutions/phonegap-nfc@a3b1e3a

from nativescript-nfc.

EddyVerbruggen avatar EddyVerbruggen commented on May 30, 2024

A PR would be very much appreciated!

from nativescript-nfc.

demetrius-tech avatar demetrius-tech commented on May 30, 2024

Sure, but it will take time as I don't have the dev env set up for iOS. I am developing for Android now. I am happy to help. I've never done a PR in my life, but I am eager to learn :D

from nativescript-nfc.

joeelia avatar joeelia commented on May 30, 2024

Perhaps we have to call queryNDEFStatus before trying writeNDEF as per https://developer.apple.com/documentation/corenfc/nfcndeftag/3075574-writendef?language=objc. Found this native Swift sample app code for iOS

    func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag]) {
        if tags.count > 1 {
            session.alertMessage = "More than 1 tags found. Please present only 1 tag."
            self.tagRemovalDetect(tags.first!)
            return
        }
        
        // You connect to the desired tag.
        let tag = tags.first!
        session.connect(to: tag) { (error: Error?) in
            if error != nil {
                session.restartPolling()
                return
            }
            
            // You then query the NDEF status of tag.
            tag.queryNDEFStatus() { (status: NFCNDEFStatus, capacity: Int, error: Error?) in
                if error != nil {
                    session.invalidate(errorMessage: "Fail to determine NDEF status.  Please try again.")
                    return
                }
                
                if status == .readOnly {
                    session.invalidate(errorMessage: "Tag is not writable.")
                } else if status == .readWrite {
                    if self.ndefMessage!.length > capacity {
                        session.invalidate(errorMessage: "Tag capacity is too small.  Minimum size requirement is \(self.ndefMessage!.length) bytes.")
                        return
                    }
                    
                    // When a tag is read-writable and has sufficient capacity,
                    // write an NDEF message to it.
                    tag.writeNDEF(self.ndefMessage!) { (error: Error?) in
                        if error != nil {
                            session.invalidate(errorMessage: "Update tag failed. Please try again.")
                        } else {
                            session.alertMessage = "Update success!"
                            session.invalidate()
                        }
                    }
                } else {
                    session.invalidate(errorMessage: "Tag is not NDEF formatted.")
                }
            }
        }
    }

But I dont know how to implement this in Nativescript :D

from nativescript-nfc.

demetrius-tech avatar demetrius-tech commented on May 30, 2024

@EddyVerbruggen: I've done good progress on implementing writeTag for iOS, it actually works, please check here: https://github.com/demetrius-tech/nativescript-nfc/blob/dev-ios-write-uid/src/nfc.ios.ts

Kindly support me in finding a solution for getting the UID #55 I'm pretty desperate.

from nativescript-nfc.

timh5 avatar timh5 commented on May 30, 2024

@demetrius-tech - what is the status of this feature? it seems that we'll have to add some obj-c code to make it work?
Is that the latest development? Can I hire you to consult on some realtime questions as we try to impliment this?
Please email me your skype or google/chat info. [email protected]

from nativescript-nfc.

demetrius-tech avatar demetrius-tech commented on May 30, 2024

@timh5 it was working in the past, with version 7. Let me check if I committed the code in my repo and I will support you for free, as I don't have much time for other projects.

from nativescript-nfc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.