我正嘗試在iPhone中創建電子名片。我爲vCard創建了一個字符串表示。我不知道如何將其轉換爲NSData格式,以便將它作爲附件發送。這是我到目前爲止有:在iPhone中創建電子名片
NSString *vCardString = [vCard getVCFString]; // returns string representation for vCard
NSData *vCardData = [vCardString dataUsingEncoding:NSUTF8StringEncoding];
[mailController addAttachmentData:vCardData mimeType:@"text/x-vcard" fileName:@"LocationInfo"];
當我在附件單擊當我做了測試電子郵件,它去創建新的聯繫人/添加爲現有的接觸。這是否正確,因爲iPhone會將其識別爲聯繫人?我想我有興趣從中獲取位置信息,但似乎並沒有出現在我的附件中。創建我的VCF代表的代碼是:
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"];
你已經得到所有聯繫人在一張v卡???如果是的話,請幫助我如何得到它,並製作一個v卡。 – parag