ABPeoplePickerNavigationController在IOS 7中崩溃

时间:2014-03-15 13:02:18

标签: iphone objective-c ios7

IOS 7中的ABPeoplePickerNavigationController出现问题,出现以下错误

*** -[ABPeoplePickerNavigationController respondsToSelector:]: message sent to deallocated instance 0x9b4b050  

在IOS 6上运行正常但是在ios 7中它给出了这个错误,僵尸启用时没有僵尸它就像

Thread 1: EXC_BAD_ACCESS(code=2,address=0x0)    

比我启用僵尸
这是我的代码

 - (void)viewDidLoad
 {  
       [super viewDidLoad];
       self.contacts = [[NSMutableArray alloc] initWithCapacity:10];
       self.addressBook=ABAddressBookCreateWithOptions(NULL, NULL);
      [self checkAddressBookAccess];
 }     
 (void)requestAddressBookAccess
 {  
        ContactsViewController * __weak weakSelf = self;

        ABAddressBookRequestAccessWithCompletion(self.addressBook, ^(bool granted,                             CFErrorRef error)
                                         {
                                             if (granted)
                                             {
                                                 dispatch_async(dispatch_get_main_queue(), ^{
                                                     [weakSelf accessGrantedForAddressBook];

                                                 });
                                             }
                                         });
 }
    -(void)accessGrantedForAddressBook
    {      
       NSMutableArray *savedContacts=[[NSMutableArray alloc] initWithArray:[DatabaseHandler getAllContacts]];
        if (savedContacts &&savedContacts.count!=0) 

       [self.contacts addObjectsFromArray:savedContacts];
    }
   - (IBAction)popUpAddExistingContact:(id)sender {    

    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    [picker setDelegate:self];
    [self presentViewController:picker animated:YES completion:nil];

 }
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{


NSString *viewControllerDesc=[viewController description];
NSString *t_st = @"ABContactViewController";
NSRange rang =[viewControllerDesc rangeOfString:t_st options:NSCaseInsensitiveSearch];

if (rang.length == [t_st length])
{
    navigationController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(addPerson:)];
}
else if([navigationController isKindOfClass:[ABPeoplePickerNavigationController class]] && [viewController isKindOfClass:[ABPersonViewController class]])
{
    ABPersonViewController *DVC=(ABPersonViewController*)viewController;
    self.currentPerson=DVC.displayedPerson;
    navigationController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(addPerson:)];

}
else{
    navigationController.topViewController.navigationItem.rightBarButtonItem = nil;
}

navigationController.topViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
}
-(IBAction)addPerson:(id)sender{

if (self.currentPerson!=NULL)
{
    CFStringRef firstName;
    int recordID;
    firstName = ABRecordCopyValue(self.currentPerson, kABPersonFirstNameProperty);
    recordID = ABRecordGetRecordID(self.currentPerson);
    MyContact *contact=[[MyContact alloc] init];
    contact.Name=(__bridge NSString *)(firstName);
    contact.contactID=[NSString stringWithFormat:@"%i",recordID];

    contact.phones=[[NSMutableArray alloc] init];
    ABMultiValueRef phones = ABRecordCopyValue(self.currentPerson, kABPersonPhoneProperty);
    for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
    {
        CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
        CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(phones, j);
        NSString *phoneNumber = (__bridge NSString *)phoneNumberRef;

        [contact.phones addObject:phoneNumber];

        CFRelease(phoneNumberRef);
        CFRelease(locLabel);
    }


    CFRelease(firstName);
    //CFRelease(lastName);
}
//[self dismissModalViewControllerAnimated:YES];

[self dismissViewControllerAnimated:YES completion:^(void ){

    [self.popUpContactView removeFromSuperview];

}];

}
一旦peoplepickercontroller被解雇app在ios 7中崩溃

*** -[ABPeoplePickerNavigationController respondsToSelector:]: message sent to deallocated instance 0xb236c00
0x17d811:  jmp    0x17d90c                  ; ___forwarding___ + 1020
Thread 1:EXC_BREAKPOINT (code=EXC_1386_BPT,sucode 0x0)

2 个答案:

答案 0 :(得分:1)

尝试在解除之前将peopleViewController委托设置为nil,并在一段时间内禁用此操作的第二次可能调用(例如,如果用户按下按钮几次)。假设您有对ABPeoplePickerNavigationController实例的引用。像self.adressBook这样的名字;

然后在解雇PeoplePickerNavigationController之前设置

self.adressBook.peoplePickerDelegate = nil
self.adressBook.delegate = nil;

并确保你没有调用你的peoplePickerNavigationController参考解雇之后,或者你对此实例的引用是,而不是分配类型。

答案 1 :(得分:0)

- (IBAction)popUpAddExistingContact:(id)sender {    

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[picker setDelegate:self];
[self presentViewController:picker animated:YES completion:nil];

}

我认为这是因为未保留创建的视图控制器, 调用[self addChildViewController:picker]或者保持一个强大的&#34;参考资料