IOS
좋아, 이것은 단지 당신에게 도움이 될 수 있습니다. 그렇게되기를 바랍니다.
내 앱에서 필자는 어떻게 든 연락처로부터 전화 번호를 알아야했습니다. 그래서 문제는 당신이 설명했듯이 - 다양한 문자들 (*)과 국가 코드없이 - 일 수 있습니다.
그래서 - 나는 ABPeoplePickerNavigationController
를 사용하여 연락처를 얻을 수 사실 수와 수에서 얻을 - 기능을 사용하여 국가 코드 : 또한
- (void)saveContactPhone:(NSString *) mContactPhone
{
if(mContactPhone && [mContactPhone length])
{
if ([mContactPhone rangeOfString:@"+"].location != NSNotFound)//this means number includes country code.
{
NSString * mCCodeString = @"";
BOOL mFound = FALSE;
for(int i = 0; i<[mContactPhone length]; i++) // check number for any obvious country code.
{
if(mFound == TRUE)
{
break;
}
mCCodeString = [mContactPhone substringToIndex:i];
mCCodeString = [[mCCodeString componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];
if([mCCodeString intValue] != 1)//because This is US/CA
{
for(int j = 0; j<[pickerViewElementArray_ count]; j++)
{
if([[pickerViewElementArray_ objectAtIndex:j] intValue] == [mCCodeString intValue])
{
mFound = TRUE;
//we got ourselves final telephone number
//and we got country code!!
mContactPhone = [mContactPhone substringFromIndex:i];
break;
}
}
}
}
if(mFound == FALSE)//If no luck finding a match - lets try again, but til index 2. (find if it is +1)
{
mCCodeString = [mContactPhone substringToIndex:2];
mCCodeString = [[mCCodeString componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];
mContactPhone = [mContactPhone substringFromIndex:1];
for(int i = 0; i<[pickerViewElementArray_ count]; i++)
{
if([[pickerViewElementArray_ objectAtIndex:i] intValue] == [mCCodeString intValue])
{
//we found it!! Its +1!!!!
mFound = TRUE;
break;
}
}
}
}
}
mContactPhone = [[mContactPhone componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];
}
당신이 국가 코드 배열을 필요 :
NSArray *pickerViewElementArray_ = [NSArray arrayWithObjects:
@"93",
@"355",
@"213",
@"1684",
@"376",
@"244",
....
: 예를 들어,
누군가를 돕는 희망!