Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
handle a call event

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?

Has anyone try to handle a call event or someting like this ?

Thanks
 
get phones out of the addressbook

I've gotten this far, but when I try to use the property called kABPersonPhoneProperty in ABPerson.h I get a return value of NSCFType.

At loggerheads. Can anyone show me how to get the phone numbers, specifically the cell phone number (kABPersonPhoneMobileLabel)?

(Also trying to get the phone number of the device itself)

i think youre talking about how to get the values in the database fields...? something like this?
PHP:
NSString *contactFirstLast = [NSString stringWithFormat:@"%@,%@", 
  ABRecordCopyValue(ref, kABPersonFirstNameProperty), 
  ABRecordCopyValue(ref, kABPersonLastNameProperty)
];
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.
 
iphone sdk address book

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?
 
use this code get person phone number
ABAddressBookRef book = ABAddressBookCreate(); // b
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(book);

NSLog(@"%@",ABMultiValueCopyValueAtIndex(ABRecordCopyValue(CFArrayGetValueAtIndex(people,indexPath.row),kABPersonPhoneProperty) ,0));

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?
 
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 :
Code:
NSString *contactFirstLast = (NSString *)lastName;
I can get all lastName, but when i try to use :
Code:
NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lastName];
it doesn't work, did you have any idea of the probleme?

It look likes
Code:
[NSString stringWithFormat: @"LN: %@", (NSString *)lastName]
and
Code:
(NSString *)lastName
are not the same kind of NSString... i really can't understand...

Thanks
 
[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. :)

The iPhone SDK _is_ under NDA and it is _not_ publicly available. And yes, you did agree not to publish any information about the iPhone SDK at all.
 
oooh ok, no problem, I'll search other site,or anywhere, with a person like you the world don't work, so, anyway I will found it, and I'll publish all, that it is not problem for me.jajaja :D secrets (like secrets expedients "X").
 
this is for add record to addressBook,

Code:
-(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);
}



this code is for remove one record in the addressbook like the record in this case with the name kate. good luck.

Code:
-(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);
		
		}
	
		
		
	}


hi, hi, :D secrets,
don't more tv, get down of the cloud programmers, we share, we aren't FBI agents, or anything else like secrets.
 
Did you link in the entire framework?

Hi I'm having the same problem, and I linked the framework using Ctrl-Click Frameworks>add>existing framework and choosing "AddressBook Framework"

I add #import <AddressBook/AddressBook.h> and then if i try

ABAddressBook *ab = [ABAddressBook sharedAddressBook];

I get the error:
ABAddressBook undeclared

but no error in the "import" line.

What am I missing to link correctly the library??

Thx,

Dani
 
hi, you have problem because in the iPhone is diferent like this:

addressBookRef ab=AddressBookCreate();

in the example above you see something like this
 
Multi values

hi there

has anyone ever managed to add an ABMutableMultiValue to an ABRecord?

what i'm trying to do is to add a new record to the addressbook.
i managed to add a record with several properties as described earlier in this thread. but when it comes to multivalues i don't have a clue...
basically i want to add for example an address. i noticed that there are constants (keys) like 'kABPersonAddressZIPKey' and a 'kABPersonAddressProperty'. but how can i add the zip key to the record?

thanks for any help.

now i came up with this.
Code:
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);

but it crashes on the last line with the messages
Code:
*** -[NSCFString count]: unrecognized selector sent to instance 0x63e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString count]: unrecognized selector sent to instance 0x63e0'
 
contactFirstLast is autorelased object, so you should not release it.

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 :
Code:
NSString *contactFirstLast = (NSString *)lastName;
I can get all lastName, but when i try to use :
Code:
NSString *contactFirstLast = [NSString stringWithFormat: @"%@", (NSString *)lastName];
it doesn't work, did you have any idea of the probleme?

It look likes
Code:
[NSString stringWithFormat: @"LN: %@", (NSString *)lastName]
and
Code:
(NSString *)lastName
are not the same kind of NSString... i really can't understand...

Thanks
 
It was a years ago (starting objective c), but thx for replying ^^
I learned a lot since that post :D
 
having problems with Program received signal: “EXC_BAD_ACCESS”.

Code:
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);
			}


wonder what im doing wrong? any help would be good thanks
 
From what i see, your error is here :

NSString *phoneNumber = ABMultiValueCopyValueAtIndex(phoneMulti, i);

your i var correspond to the address book index, not the multivalue index, you must iterate over the multivalue, you get the count with ABMultiValueGetCount();
 
pasting the whole function
Code:
- (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
	
}

Im really new would you be able to help me correct the codes.
all i want to do is draw addressbook (name,phone) into a tableview ..been banging my head against this code for a few days already .
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.