I can import contacts from the phone book and display them in a table. But I want them to display the contacts in the same order as in the phone book order .....
can someone help me how to do this and my code is as follows
self.navigationController.navigationBar.tintColor = [UIColor grayColor]; self.title = @"iPhone Contacts"; [super viewDidLoad]; wantedname= [[NSMutableArray alloc] init]; wantednumber= [[NSMutableArray alloc] init]; ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *thePeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); NSString *name; for (id person in thePeople) { name = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); NSLog(@"!!!!!! name ---> %@",name); ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty); int count1=ABMultiValueGetCount(multi); NSLog(@"%d",count1); if ([name length]>0 && count1!=0) { NSString *beforenumber = (NSString *)ABMultiValueCopyValueAtIndex(multi, 0); NSLog(@" contacts:%@",beforenumber ); NSString* removed1=[beforenumber stringByReplacingOccurrencesOfString:@"-"withString:@""]; NSString* removed2=[removed1 stringByReplacingOccurrencesOfString:@")"withString:@""]; NSString* removed3=[removed2 stringByReplacingOccurrencesOfString:@" "withString:@""]; NSString* removed4=[removed3 stringByReplacingOccurrencesOfString:@"("withString:@""]; NSString* removed5=[removed4 stringByReplacingOccurrencesOfString:@"+"withString:@""]; [wantedname addObject:name]; [wantednumber addObject:removed5];
source share