Remember that "release" isn't like "delete" in C++ or free in C. It merely reduces the reference count.
I have been trundling through the adressbook iphone framework all day looking for ways to receive "missed call" events, are an array of missed calls, or any info to do with missed calls.
Has anyone spotted any info on this anywhere?
i think youre talking about how to get the values in the database fields...? something like this?
the kABPersonBlahBlahProperty constants (or enums, i forgot what they are) are decribed in the ABPerson documentation pages. it's a little more difficult to get a hold of the multivalues, like addresses and phone numbers, ive got something working if you need it, but i feel it's not as nice as it could be.PHP:NSString *contactFirstLast = [NSString stringWithFormat:@"%@,%@", ABRecordCopyValue(ref, kABPersonFirstNameProperty), ABRecordCopyValue(ref, kABPersonLastNameProperty) ];
anyone got experience with ABMultiValueRef and ABMultiValueIdentifier. How do we initialize these variables? How can we use them to access multi value strings such as phone numbers and other contact info in the iphone addressbook sdk?
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *masterList = [[NSMutableArray alloc] init];
for (int i = 0; i < nPeople; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lastName];
CFRelease(firstName);
CFRelease(lastName);
[masterList addObject:contactFirstLast];
[contactFirstLast release];
}
self.list = masterList;
[masterList release];
NSString *contactFirstLast = (NSString *)lastName;
NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lastName];
[NSString stringWithFormat: @"LN: %@", (NSString *)lastName]
(NSString *)lastName
[Edit]: Hmm...I see other references to NDA, and although this thing is publicly available now, I know I agreed to something (didn't actually read it) when I downloaded the SDK, so I've gone back and attempted to kind of obfuscate the code so as not to give any SDK "secrets" away.![]()
-(void)editar:(id)sender{
ABAddressBookRef libroDirec = ABAddressBookCreate();
ABRecordRef persona = ABPersonCreate();
ABRecordSetValue(persona, kABPersonFirstNameProperty, @"kate" , nil);
ABRecordSetValue(persona, kABPersonLastNameProperty, @"Hutson", nil);
ABAddressBookAddRecord(libroDirec, persona, nil);
ABAddressBookSave(libroDirec, nil);
CFRelease(persona);
}
-(void)editar:(id)sender
{
ABAddressBookRef libroDirec = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(libroDirec);
CFIndex xPeople = ABAddressBookGetPersonCount(libroDirec);
for (int i=0; i <xPeople; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef nombreX = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef cadena = CFSTR("kate");
if (CFStringCompare(nombreX, cadena , 0) == kCFCompareEqualTo )
{
ABAddressBookRemoveRecord(libroDirec, ref, nil);
ABAddressBookSave(libroDirec, nil);
}
}
Did you link in the entire framework?
current = ABPersonCreate();
ABRecordSetValue(current, kABPersonFirstNameProperty, @"foo", nil);
ABRecordSetValue(current, kABPersonLastNameProperty, @"bar", nil);
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABPersonAddressProperty);
if(!ABMultiValueAddValueAndLabel(address, @"street 123", kABPersonAddressStreetKey, nil))
NSLog(@"adding value/label didn't work.");
if(!ABRecordSetValue(current, kABPersonAddressProperty, address, nil))
NSLog(@"setting value didn't work.");
if(!ABAddressBookAddRecord(addressBook, current, nil))
NSLog(@"adding didn't work.");
ABAddressBookSave(addressBook, nil);
*** -[NSCFString count]: unrecognized selector sent to instance 0x63e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString count]: unrecognized selector sent to instance 0x63e0'
Thank you for all the answers in this thread,
it was very helpful !
I've tried to use the SimpleDrillDown example from the apple dev center, and replace the list of name define in the code by the name from the address book, but as you can imagine i have a probleme.
This is the code i use to retrieve data from the addressBook.
Code:ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); NSMutableArray *masterList = [[NSMutableArray alloc] init]; for (int i = 0; i < nPeople; i++) { ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i); CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty); CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty); NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lastName]; CFRelease(firstName); CFRelease(lastName); [masterList addObject:contactFirstLast]; [contactFirstLast release]; } self.list = masterList; [masterList release];
the problem is : if i wrote the ligne :
I can get all lastName, but when i try to use :Code:NSString *contactFirstLast = (NSString *)lastName;
it doesn't work, did you have any idea of the probleme?Code:NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lastName];
It look likesandCode:[NSString stringWithFormat: @"LN: %@", (NSString *)lastName]
are not the same kind of NSString... i really can't understand...Code:(NSString *)lastName
Thanks
NSMutableArray *phones = [[NSMutableArray alloc] init];//define array geckus
CFStringRef phoneNumber;
for (int i=0;i < nPeople;i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(ref, kABPersonPhoneProperty);
NSString *phoneNumber = ABMultiValueCopyValueAtIndex(phoneMulti, i);
NSString *contactFirstLast = [NSString stringWithFormat:@"%@,%@",
ABRecordCopyValue(ref, kABPersonFirstNameProperty),
phoneNumber
];
printf("%s\n", [contactFirstLast UTF8String]);
//NSLog(mobileNo);
CFRelease(phoneNumber);
}
- (void)constructTableGroups
{
//const NSInteger NUM_ROWS = 20;
//geckus start
// open the default address book.
ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
NSLog(@"opening address book");
}
// can be cast to NSArray, toll-free
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
// CFStrings can be cast to NSString!
NSMutableArray *selectableRows = [NSMutableArray array];//define array for table geckus
NSMutableArray *phones = [[NSMutableArray alloc] init];//define array geckus
CFStringRef phoneNumber;
for (int i=0;i < nPeople;i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
//... do something with ABRecordRef...
ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(ref, kABPersonPhoneProperty);
NSString *phoneNumber = ABMultiValueCopyValueAtIndex(phoneMulti, i);
NSString *contactFirstLast = [NSString stringWithFormat:@"%@,%@",
ABRecordCopyValue(ref, kABPersonFirstNameProperty),
phoneNumber
];
printf("%s\n", [contactFirstLast UTF8String]);
//NSLog(mobileNo);
[selectableRows addObject:
[[[MultiSelectCellController alloc]
initWithLabel:[NSString stringWithFormat:contactFirstLast, i]]
autorelease]];//geckus put var into array
CFRelease(phoneNumber);
}
tableGroups = [[NSArray alloc] initWithObjects:selectableRows, nil];//init object geckus...not sure yet
//geckus end
}