Cla*_*dio 6 iphone objective-c addressbook
我想通过单击我的应用程序中的按钮来添加在iOS地址簿中保存联系人(电话号码,姓名,地址和电子邮件)的功能!我怎样才能做到这一点?
Siv*_*han 15
它如此简单,并遵循以下步骤,
首先,您有以下框架导入,
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h
Run Code Online (Sandbox Code Playgroud)
其次,在按钮操作中编写以下代码并根据需要修改代码,
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];
Run Code Online (Sandbox Code Playgroud)
}
我希望它会对你有所帮助!
Sha*_*shi 14
这是在Iphone地址簿中添加与人物图像联系的代码
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
Run Code Online (Sandbox Code Playgroud)
NSData *dataRef = UIImagePNGRepresentation(personImageView.image);
ABPersonSetImageData(person, (CFDataRef)dataRef, nil);
CFErrorRef anError = NULL;
Run Code Online (Sandbox Code Playgroud)
ABRecordSetValue(person,kABPersonFirstNameProperty,full_name,&anError);
ABRecordSetValue(person, kABPersonOrganizationProperty, companyLabel, &anError);
ABRecordSetValue(person, kABPersonJobTitleProperty, designation, &anError);
Run Code Online (Sandbox Code Playgroud)
ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);'
NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
[addressDictionary setObject:@"Chicago" forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary setObject:@"IL" forKey:(NSString *)kABPersonAddressStateKey];
[addressDictionary setObject:@"60654" forKey:(NSString *)kABPersonAddressZIPKey];
ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, (CFStringRef)@"Address", NULL);
ABRecordSetValue(person, kABPersonAddressProperty, multiAddress,&anError);
CFRelease(multiAddress);
ABMutableMultiValueRef websiteMultiValue = ABMultiValueCreateMutable(kABPersonURLProperty);
ABMultiValueAddValueAndLabel(websiteMultiValue, web_URL, (CFStringRef)@"Website", NULL);
ABRecordSetValue(person, kABPersonURLProperty, websiteMultiValue, &anError);
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABPersonEmailProperty);
ABMultiValueAddValueAndLabel(emailMultiValue, email, (CFStringRef)@"Email", NULL);
ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, &anError);
ABAddressBookAddRecord(addressBook, person, &anError);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12407 次 |
| 最近记录: |