0

can any one tell me what is the error in my code . it work fine in the simulator but in the phone and with iTunes make crash. i do not what i shall do to get the error can any one Help??

(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
   shouldContinueAfterSelectingPerson:(ABRecordRef)person 
        property:(ABPropertyID)property 
         identifier:(ABMultiValueIdentifier)identifier {
 NSString* name = (NSString *) ABRecordCopyValue(person,kABPersonFirstNameProperty );
 //self.firstName.text = name; [name release];
 NSString* name2 = (NSString *) ABRecordCopyValue (person, kABPersonLastNameProperty); 
 NSString* name1= [name stringByAppendingString(angry)" "];
 self.firstName.text = [name1 stringByAppendingString:name2];
 ABMultiValueRef phoneProperty = ABRecordCopyValue(person,property);
 NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,identifier);
 self.PhoneNumber.text = phone;
 [name release]; 
 [phone release];

 [self dismissModalViewControllerAnimated:YES];
 return NO;
}

i made changes as logancautrell advice and use ABMultiValueGetIndexForIdentifier with ABMultiValueCopyValueAtIndexas this the change was in line 11 the old line is

 NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,identifier);

the new line is

NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,ABMultiValueGetIndexForIdentifier(phoneProperty,identifier));

I test it on my iphone it work good I test it for 3 days and no error or crash BUT when I send it to iTunes they reply

Your app crashed on both Wi-Fi and cellular networks when we select a contact from the address book.

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

1

In the docs for ABMultiValueCopyValueAtIndex:

Raises an exception when out of bounds

So it is possible that the ABMultiValueIdentifier does not exist in that particular ABRecordRef. Try using ABMultiValueGetIndexForIdentifier an make sure the CFIndex returned is valid before doing the copy.

logancautrell
  • 8,762
  • 3
  • 39
  • 50
  • i do as advice i use 'ABMultiValueIdentifier' but still error please have a lock to the post agian i update it – user1001954 Oct 31 '11 at 10:03
  • Like your advice, it is better to make sure that CFIndex returned is a valid CFIndex. But in this case, how I could make sure this CFIndex is valid or not. Thanks – user454083 Apr 16 '12 at 07:36
-1

Edit: this is wrong. Methods seemed like assessor methods to me, faulty to assume autorelease was in order.

Because you release objects which you did not allocate:

[name release]; 
[phone release];
Wolfert
  • 974
  • 6
  • 12
  • The op owns those items. Note the function name: `ABRecordCopyValue()` then see the docs at *Performance > Memory Management for Core Foundation > Ownership Policy > The Create Rule*. – lowell Oct 18 '11 at 21:35
  • name and phone definitely DO need to be released, as ABRecordCopyValue will allocate new copies. In fact, name2 should be released as well. – zpasternack Oct 18 '11 at 21:38