I use this code to export contacts from an iOS phonebook to a .vcf file. I used this code for the task. But vcardString always returns nil . Please help me solve this problem.
NSMutableArray *contacts=[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:@[CNContactIdentifierKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]]]; BOOL success = [store enumerateContactsWithFetchRequest:request error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop) { [contacts addObject:contact]; }]; if (!success) { NSLog(@"error = %@", fetchError); }
source share