我在iphone地址簿中有一个手机号码,如0413 588 266
ABMutableMultiValueRef phoneno = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *phone;
if(ABMultiValueGetCount(phoneno) > 0)
{
phone = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phoneno, 0);
}
NSLog(@"phone%@",phone);
当我导入该号码时,它在IOs7中给出phone(null)值 我对Ios6没有任何问题。任何帮助都会受到赞赏。谢谢你。
答案 0 :(得分:0)
Try this way...
<强> ViewController.h 强>
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
@interface ViewController : UIViewController
<ABPeoplePickerNavigationControllerDelegate>
@property (nonatomic, retain) ABPeoplePickerNavigationController *contacts;
-(IBAction)btn_press:(id)sender;
@end
<强> ViewController.m 强>
-(IBAction)btn_press:(id)sender
{
contacts = [[ABPeoplePickerNavigationController alloc] init];
// Set the delegate.
[contacts setPeoplePickerDelegate:self];
[contacts setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]]];
[self presentViewController:contacts animated:YES completion:nil];
}
#pragma mark - AddressBook Delegate Methods
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
return YES;
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMutableMultiValueRef phoneno = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *phone;
phone = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phoneno, 0);
NSLog(@"%@",phone); // Prints 0413588266
**** NEW Update for Dismiss the Picker*******
[contacts dismissViewControllerAnimated:NO completion:nil];
return NO:
}
如果您有任何问题,请与我们联系。