gpt4 book ai didi

iphone - 如何将我的应用程序中的联系人添加到 iOS 通讯录

转载 作者:太空狗 更新时间:2023-10-30 03:38:57 26 4
gpt4 key购买 nike

我想添加在 iOS 通讯录中保存联系人(电话号码、姓名、地址和电子邮件)的功能,方法是单击我的应用程序中的一个按钮!我该怎么做?

最佳答案

非常简单,只需按照以下步骤操作,

首先,您需要导入以下框架,

#import <AddressBook/AddressBook.h>

#import <AddressBookUI/AddressBookUI.h

其次,在你的按钮 Action 中写入如下代码,根据需要修改代码,

        NSString * addressString1 = [appDelegate getCurrentSummary];

NSString * addressString2 = [appDelegate getCurrentTubeImage];

NSString * cityName = [appDelegate getCurrentcheckValue];

NSString * stateName = [appDelegate getCurrentTubeUrl];

NSString * postal = [appDelegate getCurrentViews];

NSString * emailString = [appDelegate getCurrentLink];

NSString * phoneNumber = [appDelegate getCurrentTitle];

NSString * prefName = [appDelegate getCurrentAuthor];

ABAddressBookRef libroDirec = ABAddressBookCreate();

ABRecordRef persona = ABPersonCreate();

ABRecordSetValue(persona, kABPersonFirstNameProperty, prefName, nil);

ABMutableMultiValueRef multiHome = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);

NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];

NSString *homeStreetAddress=[addressString1 stringByAppendingString:addressString2];

[addressDictionary setObject:homeStreetAddress forKey:(NSString *) kABPersonAddressStreetKey];

[addressDictionary setObject:cityName forKey:(NSString *)kABPersonAddressCityKey];

[addressDictionary setObject:stateName forKey:(NSString *)kABPersonAddressStateKey];

[addressDictionary setObject:postal forKey:(NSString *)kABPersonAddressZIPKey];

bool didAddHome = ABMultiValueAddValueAndLabel(multiHome, addressDictionary, kABHomeLabel, NULL);

if(didAddHome)
{
ABRecordSetValue(persona, kABPersonAddressProperty, multiHome, NULL);

NSLog(@"Address saved.....");
}

[addressDictionary release];

//##############################################################################

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);

bool didAddPhone = ABMultiValueAddValueAndLabel(multiPhone, phoneNumber, kABPersonPhoneMobileLabel, NULL);

if(didAddPhone){

ABRecordSetValue(persona, kABPersonPhoneProperty, multiPhone,nil);

NSLog(@"Phone Number saved......");

}

CFRelease(multiPhone);

//##############################################################################

ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABPersonEmailProperty);

bool didAddEmail = ABMultiValueAddValueAndLabel(emailMultiValue, emailString, kABOtherLabel, NULL);

if(didAddEmail){

ABRecordSetValue(persona, kABPersonEmailProperty, emailMultiValue, nil);

NSLog(@"Email saved......");
}

CFRelease(emailMultiValue);

//##############################################################################

ABAddressBookAddRecord(libroDirec, persona, nil);

CFRelease(persona);

ABAddressBookSave(libroDirec, nil);

CFRelease(libroDirec);

NSString * errorString = [NSString stringWithFormat:@"Information are saved into Contact"];

UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"New Contact Info" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[errorAlert show];

[errorAlert release];

希望对您有所帮助!

关于iphone - 如何将我的应用程序中的联系人添加到 iOS 通讯录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3334047/

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