ちょっと友達は私が...今、私は、この関数の出力から.CSVファイルを作りたい...関数から.csvファイルを書き込む方法は?
-(void)collectContacts
{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
//NSLog(@" the Name %@%",people);
for(int i = 0;i<ABAddressBookGetPersonCount(addressBook);i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(people, i);
// Get First name, Last name, Prefix, Suffix, Job title
NSString *firstName = (NSString *)ABRecordCopyValue(ref,kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(ref,kABPersonLastNameProperty);
NSString *prefix = (NSString *)ABRecordCopyValue(ref,kABPersonPrefixProperty);
NSString *suffix = (NSString *)ABRecordCopyValue(ref,kABPersonSuffixProperty);
NSString *jobTitle = (NSString *)ABRecordCopyValue(ref,kABPersonJobTitleProperty);
NSLog(@" the phoneType %@%",firstName);
NSLog(@" the phoneType %@%",lastName);
ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
NSString *phoneLabel =(NSString*) ABAddressBookCopyLocalizedLabel (ABMultiValueCopyLabelAtIndex(phones, j));
NSString *phoneNumber = (NSString *)phoneNumberRef;
NSLog(@" the phoneType %@%",phoneLabel);
NSLog(@" the phoneNumber %@%",phoneNumber);
}
CFStringRef address;
CFStringRef label;
ABMutableMultiValueRef multi = ABRecordCopyValue(ref, kABPersonAddressProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++)
{
label = ABMultiValueCopyLabelAtIndex(multi, i);
CFStringRef readableLabel = ABAddressBookCopyLocalizedLabel(label);
NSLog(@" Lable %@%",readableLabel);
address = ABMultiValueCopyValueAtIndex(multi, i);
NSLog(@" Address %@%",address);
CFRelease(address);
CFRelease(label);
}
ABMultiValueRef emails = ABRecordCopyValue(ref, kABPersonEmailProperty);
for(CFIndex idx = 0; idx < ABMultiValueGetCount(emails); idx++)
{
CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, idx);
NSString *strLbl = (NSString*) ABAddressBookCopyLocalizedLabel (ABMultiValueCopyLabelAtIndex (emails, idx));
NSLog(@" Email Lable %@%",strLbl);
NSString *strEmail_old = (NSString*)emailRef;
NSLog(@" Email-Id %@%",strEmail_old);
//[[strEmail_old componentsJoinedByString:@","] writeToFile:@"components.csv" atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}
}
//[[ContactsText componentsJoinedByString:@","] writeToFile:@"components.csv" atomically:YES encoding:NSUTF8StringEncoding error:NULL];
// NSLog(@" Data in the .CSV file = %@%",ContactsText);
}
'
を、この機能を使って、私のiphoneのすべての連絡先の詳細を持って、mはのNSLog内のすべてのデータを取得します。私はそのデータから.csvファイルを書きたいと思っています。今後データが適切ですが、書かないつもりだ.csvファイル...おかげ
上記のコードからRecorIdを取得するにはどうすればいいですか? – Vivek2012