-3

我在 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 没有任何问题。任何帮助都将不胜感激。提前致谢。

4

1 回答 1

0
Try this way...

视图控制器.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

视图控制器.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:
}

如果您有任何问题,请告诉我。

于 2013-10-16T05:55:50.800 回答