0

I am loading ABPeoplePickerNavigationController. On the click of a contact in the peoplepicker, I am checking a condition

if([navigationController isKindOfClass:[ABPeoplePickerNavigationController class]]
   && [viewController isKindOfClass:[ABPersonViewController class]]){

  //Statements

}

But in IOS 7 I have noticed that, the second condition, that is

[viewController isKindOfClass:[ABPersonViewController class]

returns NO all the time. I know that the viewcontroller that is loaded is ABPersonViewController. This was/is working fine until IOS 6. What could be the problem? Is there anyway I can get around this issue.

Edit:

The condition is checked inside UINavigationController Delegate

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

And the viewController class is shown as ABContactViewController when logged.

Xavi Valero
  • 2,047
  • 7
  • 42
  • 80
  • What does the log or debugger say about what class it is? – Mundi Oct 04 '13 at 13:28
  • @Mundi It says ABContactViewController. – Xavi Valero Oct 07 '13 at 12:10
  • @Rob in UINavigationController Delegate method – Xavi Valero Oct 07 '13 at 12:10
  • 1
    Well, that's your answer. It's not a `ABPersonViewController`. In terms of why that is one internal class versus another, I can't say (as an aside, I got a different class, `ABMembersViewController`). Could be a class cluster. The question is whether you really need to be checking the class of the controller used internally by the AddressBookUI framework. You can update your code to check for `ABContactViewController`, too, if you need to. But, it strikes me that this is always going to be fragile, subject to any internal implementation changes they make in the future. – Rob Oct 07 '13 at 12:56
  • I tried using `ABContactViewController` in place of `ABPersonViewController`. But `ABContactViewController` is not recognised – Xavi Valero Oct 07 '13 at 13:14

1 Answers1

1

When checking your class you will find that iOS7 returns a different type.

Review the logic for which you need the check. You should not have to use introspection to react appropriately to a people picker action. Just implement the standard delegate method from ABPeoplePickerNavigationControllerDelegate. In particular, you have to implement:

- (BOOL)peoplePickerNavigationController:
    (ABPeoplePickerNavigationController *)peoplePicker 
     shouldContinueAfterSelectingPerson:(ABRecordRef)person;
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • I have implemented `- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person`. I have used navigation controller delegate to have different navigation bars for contact picker and ABPersonViewController. That's why I check whether the navigationController is `ABPeoplePickerNavigationController` and viewController is `ABPersonViewController`. – Xavi Valero Oct 07 '13 at 14:52
  • 1
    That is a different nav controller. Try to implement this logic without checking the class. You should not rely on a class that Apple might change any time. – Mundi Oct 07 '13 at 20:01