I'm trying to create a vCard representation in the iPhone. I created a string representation for the vCard. I'm not sure how to convert it into the NSData form in order to mail it as an attachment. This is what I have so far:
NSString *vCardString = [vCard getVCFString]; // returns string representation for vCard
NSData *vCardData = [vCardString dataUsingEncoding:NSUTF8StringEncoding];
[mailController addAttachmentData:vCardData mimeType:@"text/x-vcard" fileName:@"LocationInfo"];
When I click on the attachment when I do a test email, it goes to the create new contact/add as existing contact. Is this correct since the iPhone recognizes it as a contact? I guess I was interested in getting the location information out of it, but that didn't seem to show up in my attachment. The code for creating my VCF representation is:
vcfString = [[NSMutableString allocWithZone:[self zone]] initWithCapacity:kDefaultStringSize];
[vcfString appendString:@"BEGIN:VCARD\n"];
[vcfString appendString:@"VERSION:3.0\n"];
if (s) {
NSMutableString *aString = [[NSMutableString alloc] initWithFormat:@"%@;", s];
[vcfString appendString:aString];
[aString replaceOccurrencesOfString:@";" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [aString length])];
street = [[NSString allocWithZone:[self zone]] initWithString:aString];
[aString release];
}
if (c) {
NSMutableString *aString = [[NSMutableString alloc] initWithFormat:@"%@;", c];
[vcfString appendString:aString];
[aString replaceOccurrencesOfString:@";" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [aString length])];
city = [[NSString allocWithZone:[self zone]] initWithString:aString];
[aString release];
}
if (st) {
NSMutableString *aString = [[NSMutableString alloc] initWithFormat:@"%@;", st];
[vcfString appendString:aString];
[aString replaceOccurrencesOfString:@";" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [aString length])];
state = [[NSString allocWithZone:[self zone]] initWithString:aString];
[aString release];
}
// TODO: look up semicolon for VCard representation
if (z) {
NSString *aString = [[NSString alloc] initWithFormat:@"%@\n", z];
[vcfString appendString:aString];
zip = [[NSString allocWithZone:[self zone]] initWithString:aString];
[aString release];
}
[vcfString appendString:@"END:VCARD"];