Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-06-2010, 05:36 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default Addressbook - ID Issue in Simulator

Hi Folks,

when I try to get the recordID from Addressbook in Simulator, the ID is every time I start the Simulator different:

Code:
ABAddressBookRef addressBook = ABAddressBookCreate();
	
	CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
	CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
	
	masterList = [[NSMutableArray alloc] init];
	userID = [[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);
		NSNumber *recordId = [NSNumber numberWithInteger: ABRecordGetRecordID(ref)];
		addId = [NSString stringWithFormat:@"%d", (NSNumber *)recordId];
		NSString *contactFirstLast = [NSString stringWithFormat: @"%@, %@",(NSString *)lastName, (NSString *)firstName];
		NSString *userId = [NSString stringWithFormat:@"%@, %@, %d", (NSString *)lastName, (NSString *)firstName, (NSNumber *)recordId];
		CFRelease(firstName);
		CFRelease(lastName);
		

		
		
		[masterList addObject:contactFirstLast];
		[userID addObject:userId];
		
		NSLog(@"masterlist: %@", masterList);
		NSLog(@"ID = %d", userID);
	//	[contactFirstLast release];
	}

First Try:

2010-03-06 11:28:21.472 myNetwork[19052:207] userIDsorted: (
"Ant, Adam, 69277408",
"Lehrner, bianca, 69279824",
"lehrner, felicitas, 69275024",
"lehrner, laetitia, 69218320",
"lehrner, stefan, 69309360",
"Stremnitzer, Michael, 69277424"
)

Second Try:

and here are the IDs diefferent:

2010-03-06 11:27:28.361 myNetwork[19013:207] userIDsorted: (
"Ant, Adam, 67196768",
"Lehrner, bianca, 67177328",
"lehrner, felicitas, 67203376",
"lehrner, laetitia, 69210880",
"lehrner, stefan, 67265888",
"Stremnitzer, Michael, 67177312"
)

Is this a behavier of the Simulator? I am trying to extend the addressbook, therefore I would need the correct ID to fill a table with data...

Thanks for your help!

Stefan
StefanL is offline   Reply With Quote
Old 03-06-2010, 08:55 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 92
Default

Change this line

[NSString stringWithFormat:@"%d", (NSNumber *)recordId];

for

[NSString stringWithFormat:@"%d",[recordId intValue]];

You are writing not the value of recordId, but the pointer to the value by using %d with the object.
fbronner is offline   Reply With Quote
Old 03-06-2010, 11:10 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Wien/Austria
Posts: 242
Default

Quote:
Originally Posted by fbronner View Post
Change this line

[NSString stringWithFormat:@"%d", (NSNumber *)recordId];

for

[NSString stringWithFormat:@"%d",[recordId intValue]];

You are writing not the value of recordId, but the pointer to the value by using %d with the object.
Hi,

thanks a lot! Worked like a charm!

BR,

Stefan
StefanL is offline   Reply With Quote
Reply

Bookmarks

Tags
addressbook, array, ids, simulator

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:14 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0