简体   繁体   English

ABPeoplePickerNavigationController在IOS 7中崩溃

[英]ABPeoplePickerNavigationController crashes in IOS 7

I have problem with ABPeoplePickerNavigationController in IOS 7 with the following error 我在IOS 7中遇到ABPeoplePickerNavigationController的问题,并出现以下错误

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

on IOS 6 it is working fine but in ios 7 it gives this error with zombies enabled without zombies it was like 在IOS 6上运行正常,但是在ios 7中,如果启用了没有僵尸的僵尸,则会出现此错误,就像

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

than i enable zombies 比我启用僵尸
here is my code 这是我的代码

 - (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];

}];

} }
as soon as peoplepickercontroller is dismissed app crashed in ios 7 一旦Peoplepickercontroller被解雇,应用程序在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)

try to set peopleViewController delegates to nil before dismissing and disable second possible call of this action during some time (like if user pressed button several times). 尝试在关闭前将peopleViewController委托设置为nil,并在一段时间内禁用此操作的第二次可能调用(例如,如果用户多次按下按钮)。 Assume you have a reference to ABPeoplePickerNavigationController instance. 假设您有对ABPeoplePickerNavigationController实例的引用。 Something name like self.adressBook; 诸如self.adressBook之类的名称;

Then before dismissing PeoplePickerNavigationController set 然后在关闭PeoplePickerNavigationController设置之前

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

and make sure that you do not call your peoplePickerNavigationController reference after dismissing or your reference to this instance is of weak , not assign type. 并确保 解雇 不要调用 peoplePickerNavigationController引用否则对此实例的引用属于weak而不是分配类型。

- (IBAction)popUpAddExistingContact:(id)sender {    

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

}

I think it is because the view controller created is not retained, Call [self addChildViewController:picker] or else maintain a "strong" reference for it 我认为这是因为未保留创建的视图控制器,请调用[self addChildViewController:picker]或为其维护“强”引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ABPeoplePickerNavigationController在初始化时崩溃 - ABPeoplePickerNavigationController crashes on init 在iOS 7中的ABPeoplePickerNavigationController中添加barButtonItems - Add barButtonItems in ABPeoplePickerNavigationController in ios 7 在iOS 8中自定义ABPeoplePickerNavigationController的导航栏 - Customizing ABPeoplePickerNavigationController's navigationbar in iOS 8 ABPeoplePickerNavigationController - ABPeoplePickerNavigationController 在使用ABPeoplePickerNavigationController之后,展开segue崩溃 - Unwind segue crashes after ABPeoplePickerNavigationController use ABPeoplePickerNavigationController仅在Simulator中被解雇时崩溃 - ABPeoplePickerNavigationController crashes while being dismissed in Simulator only 带有UITabBarController的ABPeoplePickerNavigationController在iOS8中无法正确显示 - ABPeoplePickerNavigationController with UITabBarController is not showing correctly in iOS8 删除ABPeoplePickerNavigationController中的取消按钮。 iOs 4.x中的奇怪行为 - Remove cancel button in ABPeoplePickerNavigationController. Strange behavior in iOs 4.x 在ABPeoplePickerNavigationController上取消选择RowAtIndexPath - deselectRowAtIndexPath on an ABPeoplePickerNavigationController 自定义CollectionView崩溃iOS - Custom CollectionView crashes iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM