1

我已经实现了一个将公司详细信息添加到设备电话簿的按钮。添加详细信息后,我无法从联系人屏幕再次返回应用程序。我必须点击主页按钮,然后重新启动应用程序。我一定在这里遗漏了一些基本的东西

   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;
}
4

1 回答 1

0

尝试这个 :

做完之后presentModalViewController

为了ABPersonViewController *view

你应该dismissModalViewControllerAnimated

于 2012-12-23T13:49:14.450 回答