我实施了一个按钮,可以将公司详细信息添加到设备电话簿中。当我添加细节时,我无法再从联系人屏幕返回应用程序。我必须点击主页按钮,然后重新启动应用程序。我一定错过了一些基本的东西
ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
[self.navigationController pushViewController:unknownPersonViewController animated:YES];
}
- (ABRecordRef)buildContactDetails {
NSLog(@"building contact details");
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
//Contact picture
NSData *dataRef = UIImagePNGRepresentation(contact.image);
ABPersonSetImageData(person, (__bridge_retained CFDataRef)dataRef, nil);
// Name
ABRecordSetValue(person, kABPersonFirstNameProperty, @"Don Juan", NULL);
//Phone number
ABMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiRealPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)@"0000000000", kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone, nil);
CFRelease(multiPhone);
// email
ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(email, @"hotmail.com", CFSTR("email"), NULL);
ABRecordSetValue(person, kABPersonEmailProperty, email, &error);
CFRelease(email);
// Start of Address
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDict setObject:@"High Street" forKey:(NSString *)kABPersonAddressStreetKey];
[addressDict setObject:@"0000" forKey:(NSString *)kABPersonAddressZIPKey];
[addressDict setObject:@"00000" forKey:(NSString *)kABPersonAddressCityKey];
ABMultiValueAddValueAndLabel(address,(__bridge_retained CFDataRef) addressDict, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, address, &error);
// End of Address
if (error != NULL)
NSLog(@"Error: %@", error);
return person;
}
答案 0 :(得分:0)
试试这个:
执行presentModalViewController
代表ABPersonViewController *view
dismissModalViewControllerAnimated