应用程序在使用PeoplePicker时崩溃,但不在同一视图中 [英] App crash on use of PeoplePicker, but not in same view

查看:137
本文介绍了应用程序在使用PeoplePicker时崩溃,但不在同一视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新2,我希望这有助于某人,以下链接有解决方案: https://discussions.apple.com/thread/5498630?start=0&tstart=0 ,显然这是一个iOS错误,这个工作正常。我可以创建新的sharedPicker,但是我无法从中获取任何内容或者忽略它,我不确定如何格式化链接提供的内容
任何有关的帮助都是非常欢迎。

Update 2, I hope this helps someone, there is a solutions at the following link: https://discussions.apple.com/thread/5498630?start=0&tstart=0 , evidently this is an iOS bug and this work around works. I can create the new sharedPicker, but I cannot get anything from it or dismiss it, I'm not sure how to format beyond what is supplied at the link Any help on that is very welcome.

所以现在我的问题是如何获取以下代码并实际为peoplePickerNavigationControllerDidCancel创建代码:和peoplePickerNavigationController:shouldContinueAfterSelectingPerson:
谢谢。我已离开原始帖子的大部分,以防有人出现类似的模糊问题。

So my question now is how to take the following code and actually create the code for peoplePickerNavigationControllerDidCancel: and peoplePickerNavigationController:shouldContinueAfterSelectingPerson: Thanks. I've left most of my original post in case someone has a similar vague issue.

// Convoluted workaround for the iPhone 4S crash
+ (ABPeoplePickerNavigationController *)sharedPeoplePicker {
    static ABPeoplePickerNavigationController *_sharedPicker = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedPicker = [[ABPeoplePickerNavigationController alloc] init];
    });
    return _sharedPicker;
}
// then later on, use 
[YourController sharedPeoplePicker].delegate = self;
// etc.

我当前的代码:

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier
{
    [self displayPerson:person];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    return NO;

}
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{

    //[self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)pick1:(id)sender
{
    ABPeoplePickerNavigationController *picker1 =[[ABPeoplePickerNavigationController alloc] init];
    picker1.peoplePickerDelegate = self;

    [self presentViewController:picker1 animated:YES completion:nil];

    x=1;
}

更新1,此应用程序在iPhone 4上崩溃/ 4s,但在模拟器和iPhone5中运行,如果这意味着什么。我认为只是他们有足够的力量来克服我创造的任何泄漏

Update 1, this app crashes on iPhone 4/4s, but runs in the simulator and iPhone5 if that means anything. I'm thinking its just they have enough power to get past whatever leak I have created

我有一个带视图控制器的iOS应用程序用户可以使用 ABPeoplePickerNavigationController 为应用程序选择联系人,或手动输入数字。如果手动输入数字,则没有问题。如果用户打开并且:

I have an iOS app with a view controller where the user can chose contacts for the app using ABPeoplePickerNavigationController or enter numbers manually. If numbers are entered manually there are no issues. If the user opens and:


  1. 从地址簿中选择一个新联系人

  1. Picks a new contact from the address book

更新地址簿中的联系人以在应用程序中使用

Updates a contact from the address book to use in the app

打开并取消地址簿(所有这些都不保存操作)

Opens and cancels the address book (all without saving the action)

然后我无法在没有崩溃的情况下导航到我的应用中的一个特定视图。我不知道为什么我不能去这个视图控制器,或者它为什么会导致崩溃。

Then I cannot navigate to one particular view in my app without a crash. I am at a loss why I cannot go to this one view controller, or why it causes the crash.

我使用5个不同的选择器,每个我想要的联系人一个添加并可能保存。我保存为 NSUserDefaults ,但就像我说的那样,即使从未保存选择器选项,崩溃仍然存在。我可以通过侧边栏导航导航到应用程序中的所有视图而不会发生意外,我失败的视图唯一不同的是它是从一个主视图控制器而不是我的侧边栏呈现的。

I am using 5 different pickers, one for each contact I want to add and potentially save. I save as NSUserDefaults, but like I said, the crash persists even if the picker selection is never saved. I can navigate to all view in the app from a sidebar navigation without incident, the only thing different about the view I fail on is that it is presented from one of the main view controllers and not my sidebar.

我感谢任何帮助或想法。这是我写的第一个应用程序,我正在尝试更新它并失败。我想再次使用它,以便我可以回来重构它。

I appreciate any help or thoughts. This was the first app I wrote and I'm trying to update it and failing. I want to get it functional again so I can come back and refactor it.

我的实现:

    - (IBAction)pick1:(id)sender
{
    ABPeoplePickerNavigationController *picker1 =
    [[ABPeoplePickerNavigationController alloc] init];
    picker1.peoplePickerDelegate = self;

    [self presentViewController:picker1 animated:YES completion:nil];
    x = 1;
}
- (IBAction)pick2:(id)sender
{
    ABPeoplePickerNavigationController *picker2 =
    [[ABPeoplePickerNavigationController alloc] init];
    picker2.peoplePickerDelegate = self;

    [self presentViewController:picker2 animated:YES completion:nil];
    x=2;
}
- (IBAction)pick3:(id)sender
{
    ABPeoplePickerNavigationController *picker3 =
    [[ABPeoplePickerNavigationController alloc] init];
    picker3.peoplePickerDelegate = self;

    [self presentViewController:picker3 animated:YES completion:nil];
    x=3;
}
- (IBAction)pick4:(id)sender
{
    ABPeoplePickerNavigationController *picker4 =
    [[ABPeoplePickerNavigationController alloc] init];
    picker4.peoplePickerDelegate = self;

    [self presentViewController:picker4 animated:YES completion:nil];
    x=4;
}
- (IBAction)pick5:(id)sender
{
    ABPeoplePickerNavigationController *picker5 =
    [[ABPeoplePickerNavigationController alloc] init];
    picker5.peoplePickerDelegate = self;

    [self presentViewController:picker5 animated:YES completion:nil];
    x=5;
}
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    [self displayPerson:person];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];


    return NO;
}

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier
{
    return NO;
}
- (void)displayPerson:(ABRecordRef)person
{
    NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person,
                                                                    kABPersonFirstNameProperty);


    NSString* phone = nil;
    ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,
                                                     kABPersonPhoneProperty);
    if (ABMultiValueGetCount(phoneNumbers) > 0) {
        phone = (__bridge_transfer NSString*)
        ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
    } else {
        phone = @"[None]";
    }
    if (x==1){
        firstName1.text = name;
        contact1.text = phone;
    }
    if (x==2){
        firstName2.text = name;
        contact2.text = phone;
    }
    if (x==3){
        firstName3.text = name;
        contact3.text = phone;
    }
    if (x==4){
        firstName4.text = name;
        contact4.text = phone;
    }
    if (x==5){
        firstName5.text = name;
        contact5.text = phone;
    }

}


推荐答案

很抱歉回答我自己的问题,但是另一项需要改变的工作是使用CF Retain来纠正我遇到的过度释放。我保留了这个人和peoplePicker,所有人都得到了解决。感谢所有试图帮我解决此问题的人。

Sorry to answer my own question, but another work around to this that requires little change is to use CF Retain to correct the over release I was experiencing. I retained the person and the peoplePicker and all was resolved. Thanks for everyone who tried to help me solve this.

- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{

    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
   CFRetain((__bridge CFTypeRef)(peoplePicker));
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier
{
    [self displayPerson:person];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    CFRetain(person);
    CFRetain((__bridge CFTypeRef)(peoplePicker));
    return NO;

}

这篇关于应用程序在使用PeoplePicker时崩溃,但不在同一视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆