Estoy tratando de obtener una URL de una simple frase NSString. Para que utilizo NSDataDetector en el siguiente código:NSDataDetector con NSTextCheckingTypeLink detecta URL y PhoneNumbers!
NSString *string = @"This is a sample of a http://abc.com/efg.php?EFAei687e3EsA sentence with a URL within it and a number 097843.";
NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [linkDetector matchesInString:string options:0 range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypeLink) {
NSString *matchingString = [match description];
NSLog(@"found URL: %@", matchingString);
}
}
El resultado es que se encuentra la URL y el número. El número se detecta como un número de teléfono:
found URL: http://abc.com/efg.php?EFAei687e3EsA
found URL: tel:097843
¿Eso es un error? ¿Alguien podría decirme cómo obtener la URL sin ese número de teléfono?
Entendido! Para evitar obtener un número de teléfono, estoy verificando las primeras siete letras como: NSString * httpString = [aString substringWithRange: NSMakeRange (0,7)]; if ([httpString isEqualToString: @ "http: //"]) { // mi código } – user689081
Es realmente extraño ya que hay otro NSTextCheckingType llamado 'NSTextCheckingTypePhoneNumber' específicamente para verificar los números de teléfono. – an0