gpt4 book ai didi

iphone - 如何在将数据保存到 iPhone 通讯录后立即显示一个人的记录?

转载 作者:行者123 更新时间:2023-11-28 17:48:15 24 4
gpt4 key购买 nike

这是我的代码,它运行完美,其中 my_value 是一个带有分隔符“,”的字符串。一切正常,但我想在保存后显示地址簿中的人员记录,所以在函数中

  if(isSaved) {
// **** code here ***
}

这里是完整的函数

- (void) addToAgenda: (NSString*) my_value{ 

//NSArray *strings = [my_value componentsSeparatedByString: @","];
NSArray *dati=[[NSArray alloc] initWithArray:[my_value componentsSeparatedByString:@","]];
NSString *userwebsite = [dati objectAtIndex:0];
NSString *fname = [dati objectAtIndex:1];
NSString *lname = [dati objectAtIndex:2];
NSString *useremail = [dati objectAtIndex:3];;
NSString *usermobile = [dati objectAtIndex:4];
NSString *usercompany = @"xxx";

ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;

// fisrst name
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, fname, &anError);

// last name
ABRecordSetValue(aRecord, kABPersonLastNameProperty, lname, &anError);

// Phone Number.
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multi, (CFStringRef)usermobile, kABWorkLabel, NULL);
ABRecordSetValue(aRecord, kABPersonPhoneProperty, multi, &anError);
CFRelease(multi);

// Company
ABRecordSetValue(aRecord, kABPersonDepartmentProperty, usercompany, &anError);

// email
NSLog(@"%@", useremail);
ABMutableMultiValueRef multiemail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiemail, (CFStringRef)useremail, kABWorkLabel, NULL);
ABRecordSetValue(aRecord, kABPersonEmailProperty, multiemail, &anError);
CFRelease(multiemail);

// website
NSLog(@"%@", userwebsite);
ABMutableMultiValueRef multiweb = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiweb, (CFStringRef)userwebsite, kABWorkLabel, NULL);
ABRecordSetValue(aRecord, kABPersonURLProperty, multiweb, &anError);
CFRelease(multiemail);

if (anError != NULL)
NSLog(@"error while creating..");

CFStringRef personname, personlname, personcompind, personemail, personwebsite, personcontact;

personname = ABRecordCopyValue(aRecord, kABPersonFirstNameProperty);
personlname = ABRecordCopyValue(aRecord, kABPersonLastNameProperty);
personcompind = ABRecordCopyValue(aRecord, kABPersonDepartmentProperty);
personemail = ABRecordCopyValue(aRecord, kABPersonEmailProperty);
personwebsite = ABRecordCopyValue(aRecord, kABPersonURLProperty);
personcontact = ABRecordCopyValue(aRecord, kABPersonPhoneProperty);

ABAddressBookRef addressBook;
CFErrorRef error = NULL;
addressBook = ABAddressBookCreate();

BOOL isAdded = ABAddressBookAddRecord (addressBook, aRecord, &error);

if(isAdded){

NSLog(@"added..");
}
if (error != NULL) {
NSLog(@"ABAddressBookAddRecord %@", error);
}
error = NULL;

BOOL isSaved = ABAddressBookSave (addressBook, &error);

if(isSaved) {

// **** code here ***
}

if (error != NULL) {

NSLog(@"ABAddressBookSave %@", error);
UIAlertView *alertOnChoose = [[UIAlertView alloc] initWithTitle:@"Unable to save this time" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertOnChoose show];
[alertOnChoose release];
}

CFRelease(aRecord);
CFRelease(personname);
CFRelease(personlname);
CFRelease(personcompind);
CFRelease(personcontact);
CFRelease(personemail);
CFRelease(personwebsite);
CFRelease(addressBook);
}

最佳答案

您可以使用类似ABPersonViewController 的东西来显示aRecord。由于它是 UIViewController 的子类,您可以像显示任何其他 View Controller 一样显示它,例如将它推送到您的导航 Controller 堆栈或以模态方式呈现。

关于iphone - 如何在将数据保存到 iPhone 通讯录后立即显示一个人的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3743590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com