checking whether the number is in phone contacts are not
<p>i want to check whether the given number is in phone book or not programatically .</p>

<p>i am able to display the contact name of the given number if it is exists in phone book but the program crashes when there is no contact with that number in phone book ...
but what i want is to display name if it exists in phone book..... and display the number if if is not in phone book......
and my code is as follows....</p>

<p>NSMutableArray *names = [[NSMutableArray alloc] init];
    NSMutableArray *phonenumbers = [[NSMutableArray alloc] init];</p>

<pre><code>ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *thePeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);

NSString *name;
for (id person in thePeople)
{

    name = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    NSLog(@"!!!!!! name ---&gt; %@",name);
    ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
    int count1=ABMultiValueGetCount(multi);
    NSLog(@"%d",count1);

    if ([name length]&gt;0 &amp;&amp; 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:@""];

        [names addObject:name];
        [phonenumbers addObject:removed5];

    }

}
int barindex = -1;
barindex = [phonenumbers indexOfObject:number];
if(barindex == -1)
    return number;
else
return [names objectAtIndex:barindex];
</code></pre>

<p>can any one please help me how to do that.............</p>

<p>thank you.......</p>
