freshking
freshking

Reputation: 1864

Generate vCard without image

I am currently generating vCards from my Address Book via this function:

ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL, nil);

NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

if (!lastName) lastName = @"";
if (!firstName) firstName = @"";

NSString *name = [NSString stringWithFormat:@"%@ %@",firstName, lastName];

CFArrayRef contact = ABAddressBookCopyPeopleWithName(ab, (__bridge CFStringRef)(name));    

CFDataRef vcard = (CFDataRef)ABPersonCreateVCardRepresentationWithPeople(contact);

This works just fine but I don't want any images in my vCard. Is there any way to generate a vCard without getting the image?

Upvotes: 1

Views: 545

Answers (1)

freshking
freshking

Reputation: 1864

I created a workaround for this by simply removing the the photo part from the string as so:

- (NSString *)removeImageFromVCF:(NSString *)yourString {

NSScanner *theScanner;
NSString *text = nil;

theScanner = [NSScanner scannerWithString:yourString];

if ([yourString rangeOfString:@"X-SOCIALPROFILE"].location == NSNotFound) {

    while ([theScanner isAtEnd] == NO) {

        [theScanner scanUpToString:@"PHOTO" intoString:NULL] ;
        [theScanner scanUpToString:@"END:VCARD" intoString:&text] ;

        yourString = [yourString stringByReplacingOccurrencesOfString:
                      [NSString stringWithFormat:@"%@", text] withString:@""];
    }

}else{

    while ([theScanner isAtEnd] == NO) {

        [theScanner scanUpToString:@"PHOTO" intoString:NULL] ;
        [theScanner scanUpToString:@"X-SOCIALPROFILE" intoString:&text] ;

        [theScanner scanUpToString:@"END:VCARD" intoString:NULL];

        yourString = [yourString stringByReplacingOccurrencesOfString:
                      [NSString stringWithFormat:@"%@", text] withString:@""];


    }

}

return yourString;

}

Hopefully this will help somebody else.

Upvotes: 0

Related Questions