0
夥計們正在爲Ios調用應用程序,所以很自然我有一個撥號盤集成。 這個問題是爲了從我的撥號盤上撥打的號碼獲取聯繫人詳細信息,我在其他屏幕上顯示。Ios獲取聯繫人聯繫方式的詳細信息
這裏是我的代碼
+(PhoneContactModel*) getContactFrom:(NSString *)calledPhoneNumber{
PhoneContactModel *contact=[[PhoneContactModel alloc]init];
ABAddressBookRef addressBook = [AppUtils getCompatibleAdressBook];
CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex n = ABAddressBookGetPersonCount(addressBook);
for(int i = 0 ; i < n ; i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
//CFRelease(phones);
NSString *phoneNumber = (__bridge NSString *)phoneNumberRef;
NSLog(@"apputil number %@",[AppUtils getNumberSanatized:phoneNumber]);
if ([phoneNumber isEqualToString:calledPhoneNumber]){
NSLog(@"apputil number matched %@",[AppUtils getNumberSanatized:phoneNumber]);
contact.strFullName = (__bridge_transfer NSString *) ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString *) ABRecordCopyValue(ref, kABPersonLastNameProperty);
contact.strFullName=[contact.strFullName stringByAppendingString:@" "];
if (lastName!=nil){
contact.strFullName=[contact.strFullName stringByAppendingString:lastName];
}
contact.imgContactImge=[AppUtils imageForContact:ref];
contact.strNumber=phoneNumber;
return contact;
}
}
}
contact.strFullName = calledPhoneNumber;
return contact;
}
看起來像如果我有號64xxxx聯繫人的問題...我撥打+ 164xxxx ..從我的撥號盤我沒有得到接觸詳細信息,還可以看到,在上面的方法,我必須運行一個循環找即使有匹配匹配的聯繫人,那麼,有沒有更好的方法,在那裏做同樣的
感謝
而不是你可以使用// if([phoneNumber isEqualToString:calledPhoneNumber]){// NSString * string = @「hi bla bla」;如果([string rangeOfString:@「bla」]。location == NSNotFound){ NSLog(@「string does not contain bla」);其他{ NSLog(@「string contains bla!」); } 也可以刪除「+」,如果它存在於字符串 –
生病請嘗試這個dinesh,但不要你的東西我的方法可能會慢或阻止,因爲我使用循環,Ain'there任何其他優化的方法 – Rohit
一種方法可以您使用核心數據將所有聯繫人保存在應用程序中,然後使用NSPredicate進行獲取但是這需要一些編碼。這種方法也很好,不會花費任何時間讓你的應用變慢。 –