gpt4 book ai didi

iphone - ABPeoplePickerNavigationController 在 IOS 7 中崩溃

转载 作者:行者123 更新时间:2023-12-03 21:15:06 24 4
gpt4 key购买 nike

我在 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 被解雇,应用程序就会在 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)

最佳答案

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

然后在关闭 PeoplePickerNavigationController 之前设置

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

并确保解除之后您不会调用您的peoplePickerNavigationController引用,或者您对此实例的引用是,而不是>分配类型。

关于iphone - ABPeoplePickerNavigationController 在 IOS 7 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22424159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com