iOS11,複製電話本聯繫人電話時,複製的不是11位的手機號而是15位,這是系統bug,iOS如何複製電話本號碼消除空格呢,直接上代碼app
//結束編輯
-(void)textViewDidEndEditing:(UITextView *)textView
{
// 去掉數字
NSLog(@"%lu",(unsigned long)textView.text.length);
NSMutableString *strippedString = [NSMutableString
stringWithCapacity:textView.text.length];
NSScanner *scanner = [NSScanner scannerWithString:textView.text];
NSCharacterSet *numbers = [NSCharacterSet
characterSetWithCharactersInString:@"0123456789"];
while ([scanner isAtEnd] == NO) {
NSString *buffer;
if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
[strippedString appendString:buffer];
}
else {
[scanner setScanLocation:([scanner scanLocation] + 1)];
}
}
NSLog(@"%@", strippedString);
textView.text = strippedString;
NSLog(@"%lu",(unsigned long)textView.text.length);
}ip