Iphone 在objective-c中创建vCard?
我想在目标c中创建vCard() 你能给我举个例子说明怎么做吗? 还有一个问题,我可以在sms中附加vCard吗Iphone 在objective-c中创建vCard?,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我想在目标c中创建vCard() 你能给我举个例子说明怎么做吗? 还有一个问题,我可以在sms中附加vCard吗 谢谢在纯文本文件中,卡片格式相对简单。这里有一个很好的概述: 您应该能够自己构造文件 // Create vcd file all contacts - (void)CreateVCardfile { NSMutableArray *contactsArray=[[NSMutableArray alloc] init]; CNContactStore *store = [[CNCon
谢谢在纯文本文件中,卡片格式相对简单。这里有一个很好的概述: 您应该能够自己构造文件
// Create vcd file all contacts
- (void)CreateVCardfile {
NSMutableArray *contactsArray=[[NSMutableArray alloc] init];
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if (!granted)
{
dispatch_async(dispatch_get_main_queue(), ^{
});
return;
}
NSMutableArray *contacts = [NSMutableArray array];
NSError *fetchError;
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[[CNContactVCardSerialization descriptorForRequiredKeys], [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]]];
BOOL success = [store enumerateContactsWithFetchRequest:request error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop) {
[contacts addObject:contact];
}];
if (!success)
{
NSLog(@"error = %@", fetchError);
}
CNContactFormatter *formatter = [[CNContactFormatter alloc] init];
for (CNContact *contact in contacts)
{
[contactsArray addObject:contact];
}
NSData *vcardString =[CNContactVCardSerialization dataWithContacts:contactsArray error:&error];
NSString* vcardStr = [[NSString alloc] initWithData:vcardString encoding:NSUTF8StringEncoding];
NSLog(@"vcardStr = %@",vcardStr);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *folderPath = [paths objectAtIndex:0];
NSString *filePath = [folderPath stringByAppendingPathComponent:@"Contacts.vcf"];
[vcardStr writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
NSArray *objectsToShare = @[fileUrl];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
}];
}您想创建Vcard,以及如何创建Vcard?解释想法我有一些知识,因为我在一些vCard应用程序中工作过。我想在目标c中创建vCard添加字段,并能够将vCard视为vCard外观。我想创建vCard或扫描vCard,因此您想使用联系人列表中的详细信息生成vCard。不,我想使用我在中选择的字符串生成vCard代码