【发布时间】:2015-08-29 23:47:58
【问题描述】:
我正在制作一个社交应用程序,我必须使用姓名和电话号码来实现 ABAddressBook。
我想格式化电话号码,例如:+33 6 01 23 45 67 变为 0601234567(法国电话号码)。所以,我想删除空格,并将+33 转换为0
有些电话号码没有空格,但有些有。我不知道为什么。和以+33 6 开头的数字不保存。
ABMultiValueRef phones = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty);
for (NSUInteger j = 0; j < ABMultiValueGetCount(phones); j++) {
NSMutableString *phone = [CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, j)) mutableCopy];
[phone replaceOccurrencesOfString:@" " withString:@"" options:0 range:NSMakeRange(0, phone.length)];
[phone replaceOccurrencesOfString:@"(" withString:@"" options:0 range:NSMakeRange(0, phone.length)];
[phone replaceOccurrencesOfString:@")" withString:@"" options:0 range:NSMakeRange(0, phone.length)];
[phone replaceOccurrencesOfString:@"-" withString:@"" options:0 range:NSMakeRange(0, phone.length)];
[phone replaceOccurrencesOfString:@"+33" withString:@"0" options:0 range:NSMakeRange(0, phone.length)];
[phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (((j == 0) && [phone hasPrefix:@"06"]) || ((j == 0) && [phone hasPrefix:@"07"])) person.mainNumber = phone;
else if ((j==1) && [phone hasPrefix:@"06"]) person.mainNumber = phone;
else if ((j==2) && [phone hasPrefix:@"06"]) person.mainNumber = phone;
else if ((j==3) && [phone hasPrefix:@"06"]) person.mainNumber = phone;
}
CFRelease(phones);
【问题讨论】:
标签: ios objective-c format abaddressbook nsmutablestring