chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 559 forks source link

Document how to create VCards #120

Closed JohnMcLear closed 10 years ago

JohnMcLear commented 10 years ago

This is as much a job for me as anyone else, Txt and URIs can easily be created but there is no clear docs for how to create a vcard.. @Don if you have some thoughts on this I'd be all ears :)

don commented 10 years ago

Use a MIME Media record to write a vCard

payload = 'BEGIN:VCARD\n' +
    'VERSION:2.1\n' +
    'N:Coleman;Don;;;\n' +
    'FN:Don Coleman\n' +
    'ORG:Chariot Solutions;\n' +
    'URL:http://chariotsolutions.com\n' +
    'TEL;WORK:215-358-1780\n' +
    'EMAIL;WORK:info@chariotsolutions.com\n' +
    'END:VCARD';
record = ndef.mimeMediaRecord('text/x-vCard', nfc.stringToBytes(payload));

The biggest problem is a full vCard can easily exceed the capacity of a small tag.

JohnMcLear commented 10 years ago

I knew it'd be something simple. Cheers for replying and closing.

I should be able to craft this into the NFC Ring Control app without too much drama.. Might do a little phonegap-nfc example/demo showing the cordova contacts api and phonegap-nfc plugin just because it might help others in the future to use mime types.

don commented 10 years ago

That's a good idea to read from the contacts, create a vCard and write to the tag. Hopefully you know the capacity of the tag and build a vCard that will fit. IIRC, I got most of the vCard info from http://en.wikipedia.org/wiki/VCard

JohnMcLear commented 10 years ago

Simple example of writing a vcard: https://github.com/JohnMcLear/phonegap-nfc-vcard Advanced example of getting a contact from the cordova contact API and writing vcard of that contact: https://github.com/JohnMcLear/phonegap-nfc-vcard/tree/find-and-write

Apache 2 license do whatever ya want goodness

PS copied most of your coding practices but not all, I don't like how you sometimes define variables on trailing lines and I try to keep object oriented functionality outside of app.. I dislike the notion of "app" in cordova.