1

我目前正在通过此功能从我的地址簿生成 vCard:

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);

这工作得很好,但我不希望我的 vCard 中有任何图像。有没有办法在不获取图像的情况下生成 vCard?

4

1 回答 1

0

我为此创建了一个解决方法,只需从字符串中删除照片部分,如下所示:

- (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;

}

希望这会对其他人有所帮助。

于 2013-03-01T12:46:04.237 回答