从设备上的iPhone地址簿ERROR获取电话号码

时间:2011-10-18 20:30:11

标签: ios iphone objective-c

任何人都可以告诉我代码中的错误是什么。它在模拟器中工作正常,但在手机和iTunes崩溃。我不知道我该怎么做才能得到错误 可以任何一个帮助?

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

我做了更改为logancautrell建议并使用ABMultiValueGetIndexForIdentifier和ABMultiValueCopyValueAtIndexas这个更改在第11行 旧行是

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

新行是

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

我在我的iphone上测试它运行良好我测试了3天没有错误或崩溃但是当我发送到iTunes时他们回复

  

当我们从地址簿中选择联系人时,您的应用在Wi-Fi和蜂窝网络上都会崩溃。

2 个答案:

答案 0 :(得分:1)

在ABMultiValueCopyValueAtIndex的文档中:

Raises an exception when out of bounds

因此ABMultiValueIdentifier可能不存在于特定的ABRecordRef中。尝试使用ABMultiValueGetIndexForIdentifier,确保在复制之前返回的CFIndex有效。

答案 1 :(得分:-1)

编辑:这是错误的。方法似乎对我来说是评估方法,因为假设自动释放是有序的。

  

因为您释放了未分配的对象:

[name release]; 
[phone release];
相关问题