Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How do you make a vCard?

How do you make a vCard?
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
May 6, 2002, 11:08 PM
 
I would like to make an app (in Cocoa Java), where the user enters some information into text fields which can then be written to a vCard file. I am a novice programmer with most of my experience in Java. I looked at the "guts" of some vCards and they look pretty easy to format, but I don't know how to write the files to a disk and put the write extension on. I know how to implement NSSavePanel, but not sure where to go from here.

Any help greatly appreciated.
     
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status: Offline
Reply With Quote
May 12, 2002, 02:47 PM
 
If you haven't already, check out the AppKit class:

NSFileWrapper

and the 'writeToFile' method.

When bringing up the NSSavePanel, make sure you setRequiredFileType to be your vcard type. After setting getting the file name from your NSSavePanel, create the NSFileWrapper instance with the path, and execute the writeToFile method.
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
May 12, 2002, 03:12 PM
 
Thanks Brad. I have been checking out the NSFileWrapper class. I was wondering, I have been using the writeFile method for to save a .txt file. I can get it to save the file in the appropriate place, but when I go to the .txt file in the Finder, it is a folder and only alias. Any idea of why this is?
     
Mac Elite
Join Date: Oct 2000
Location: Oakland, CA
Status: Offline
Reply With Quote
May 12, 2002, 05:09 PM
 
I have been looking into the same thing, but I have used Applescript Studio though, since I don't know Obj C. However, I do have it working if you want check out what I have let me know. I am using it for storing logins and passwords and addresses when doing various websites. Right now I have it where you can enter the info and it saves to a vCard file for import to the iPod. I plan to add a way to send the file straight to the iPod next. The problem I'm having though is trying to give the saved file a custom .icns file instead of the generic text file.

[ 05-12-2002: Message edited by: exca1ibur ]
     
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status: Offline
Reply With Quote
May 12, 2002, 10:18 PM
 
Originally posted by macrophyllum:
<STRONG>Thanks Brad. I have been checking out the NSFileWrapper class. I was wondering, I have been using the writeFile method for to save a .txt file. I can get it to save the file in the appropriate place, but when I go to the .txt file in the Finder, it is a folder and only alias. Any idea of why this is?</STRONG>
Weird... I haven't tried it lately (and never in Cocoa-Java), but check to see if

yourFileWrapper.isDirectory() returns true (also check out yourFileWrapper.isSymbolicLink() which may make it look like an alias).

Also, when you instantiate your NSFileWrapper, are you using

public NSFileWrapper( String path, boolean symLink)

? If so, is symLink FALSE, and the path a string which does not end with '/'?

In Objective-C, there is a instantiating method 'initRegularFileWithContents:', so there is a bit of a difference...
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
May 12, 2002, 10:37 PM
 
I got it to work by using the NSData class; it has a writeToURL() method. Now it works great!

I heard that Apple will be releasing some new frameworks for working with vCards, but I don't think they are available yet.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:54 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2