У меня проблемы с доступом к свойству адреса моих контактов.Я могу успешно получить доступ к номеру телефона или адресу, используя приведенный ниже метод, но при получении только свойства адреса я получаю утечку с ответственным фреймом "+ [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. Если был выбран объект Person 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) executeSelector: 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];