我无法正常访问我的联系人的地址属性。我能够使用下面的方法成功访问电话号码或地址,但是当获取地址属性时,我会在负责框架处发生泄漏,并显示“+ [ABStyleProvider]”。任何人都可以告诉我这是什么意思或我做错了什么?内存泄漏使用AddressBook:泄漏对象“ABStyleProvider”
下面是ABPeoplePickerNavigationController。以下是我如何处理电话号码或地址的选择。我使用NSMutableString和CFDictionaryGetValueIfPresent来仅收集非空数据并将其作为字符串返回。
感谢您的帮助和任何建议,将不胜感激。
if (person) {
if (property == kABPersonPhoneProperty){
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty); //Dane
if (phones) {
CFIndex index = ABMultiValueGetIndexForIdentifier(phones, identifier);
NSString *phone = (NSString*)ABMultiValueCopyValueAtIndex(phones, index);
//Set textField with Phone Number
MyTextField.text = phone;
[phone release];
CFRelease(phones);
[self doneEnteringPhoneNumber];
}
}
else if (property == kABPersonAddressProperty){
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty); //Dane
if (addresses) {
CFIndex index = ABMultiValueGetIndexForIdentifier(addresses, identifier);
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, index);
//Get Only valid address values (Non-Null)
CFTypeRef aString;
NSMutableString * address = [NSMutableString string];
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressStreetKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressCityKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressStateKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressZIPKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
CFRelease(dict);
//Set Address
DestinationTextField.text = address;
CFRelease(addresses);
//Auto trigger search for address
[self doneEnteringAddress];
}
}
}
作为后续,我完全删除所有代码,只是显示,并在下列情况下,驳回了peoplePickerController: 1.如果一个人选择 2.如果属性选择 3.如果用户取消 并在每种情况下,我看到上述内存泄漏。
仪器扩展详细泄漏:(16字节)。每次回到我的主视图都会泄漏?
0 libSystem.B.dylib calloc
1 libobjc.A.dylib _internal_class_createInstanceFromZone
2 libobjc.A.dylib class_createInstance
3 CoreFoundation +[NSObject(NSObject) allocWithZone:]
4 CoreFoundation +[NSObject(NSObject) alloc]
5 CoreFoundation +[NSObject(NSObject) new]
6 AddressBookUI +[ABStyleProvider defaultStyleProvider]
7 AddressBookUI -[ABPeoplePickerNavigationController initAsAddressBook:withAddressBook:]
8 AddressBookUI -[ABPeoplePickerNavigationController init]
9 Cartis -[MainViewController getContactPhoneNumber:] ****************.m:707
10的CoreFoundation - [NSObject的(NSObject的)performSelector:withObject:withObject:]
除了这里是我的PeoplePicker初始化和从IBAction为方法
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray * displayedProperties = [NSArray arrayWithObjects:
[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonAddressProperty],
nil];
picker.displayedProperties = displayedProperties;
//Dane - here
[self presentModalViewController:picker animated:YES];
[picker release];
作为一个后续,我完全删除了所有这些代码,只是在以下情况下显示和解除了peoplePickerController: – user582546 2011-01-21 07:59:15