0
我想檢查給定的號碼是否在電話簿或編程方式。檢查號碼是否在手機通訊錄不是
我能夠顯示給定數量的聯繫人姓名,如果它是存在於電話簿,但程序崩潰時,有電話本與這個數字沒有聯繫...... ,但我想要的是顯示名稱如果它存在於電話簿.....如果,如果不是在電話簿...... 和我的代碼如下顯示的數量....
的NSMutableArray *名稱= [[NSMutableArray裏alloc] init]; NSMutableArray * phonenumbers = [[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:@""];
[names addObject:name];
[phonenumbers addObject:removed5];
}
}
int barindex = -1;
barindex = [phonenumbers indexOfObject:number];
if(barindex == -1)
return number;
else
return [names objectAtIndex:barindex];
任何一個可以請幫我該怎麼做.............
謝謝.......
你在使用來電顯示嗎? – Jorge 2011-04-08 06:24:01
不,我有一個文本框,我將手動輸入數字,我必須顯示名稱,如果數字存在,否則顯示我必須顯示數字..... – user564963 2011-04-08 06:27:36
你需要,只要用戶是打字或在輸入號碼後按下按鈕? – Jorge 2011-04-08 06:30:50