Извлечь всю адресную книгу из ABpeson target c iPhone - PullRequest
0 голосов
/ 21 июля 2010

Это мой код:

    ABAddressBookRef _addressBookRef = ABAddressBookCreate ();
    NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);
    NSMutableArray* _allItems = [[NSMutableArray alloc] initWithCapacity:[allPeople count]]; // capacity is only a rough guess, but better than nothing
  for (id record in allPeople) {
        CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty);
        NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
        CFRelease(phoneProperty);
        for (NSString *phone in phones) {
            NSString* compositeName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
            NSString* field = [[NSString] stringWithFormat@"%@:%@",compositeName,phone];            
            [compositeName release];
            [_allItems addObject:field];
            for ( NSString *txt in _allItems )
            {
                contacts.text = [contacts.text stringByAppendingFormat:@"%@\n",txt];
            }
        }
        [phones release];
    }


    CFRelease(_addressBookRef);
    [allPeople release];
    allPeople = nil;

}

В основном я хочу выгрузить всю адресную книгу в UItextView с именем contacts.text и иметь только имя и номер, такие как NAME: NUMBER, разделенные: я сейчас получаю сообщение об ошибке

 NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];

любая помощь будет потрясающей: D

Спасибо Мейсон

1 Ответ

0 голосов
/ 21 июля 2010
 NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];

должно быть

 NSString* field = [NSString stringWithFormat:@"%@:%@",compositeName,phone];
...