0

「-」「」「」で数字をそのまま取得したい。電話帳から連絡先を取得している間、ここに私のコードがあります。
私の主な動機は、+ が存在する場合に番号から国コードを抽出することです。
また、国コードにアクセスする他の方法があれば教えてください。

    - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController                                                        *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier;
    {
        if (property == kABPersonPhoneProperty) {
            ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
    for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) {
        if(identifier == ABMultiValueGetIdentifierAtIndex (multiPhones, i)) {
            CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(multiPhones, i);
            CFRelease(multiPhones);
            NSString *phoneNumber = (__bridge NSString *) phoneNumberRef;
            CFRelease(phoneNumberRef);
            if ([phoneNumber rangeOfString:@"+"].location == NSNotFound) {
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"." withString:@""];

                self.lblMobileNumber.text = [NSString stringWithFormat:@"%@", phoneNumber];
            } else {
                NSArray *PhoneNumberComponents = [phoneNumber componentsSeparatedByString:@" "];
                NSString * strCountryCode = PhoneNumberComponents[0] ;
                [self.btnCountryCode setTitle:strCountryCode forState:UIControlStateNormal];

                phoneNumber= [phoneNumber stringByReplacingOccurrencesOfString:PhoneNumberComponents[0] withString:@""];
                NSLog(@"countryCodeSepratedStr%@",phoneNumber);
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
                phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"." withString:@""];
                self.lblMobileNumber.text = [NSString stringWithFormat:@"%@", phoneNumber];

            }

        }
    }
  }
  return NO;
 }
4

1 に答える 1