NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];//建立檢測器,檢測類型是linke(可改爲檢測別的) NSArray *matches = [detector matchesInString:textString options:0 range:NSMakeRange(0, textString.length)];//檢測字符串 for (NSTextCheckingResult *match in matches) { if ([match resultType] == NSTextCheckingTypeLink) { NSRange matchRange = [match range];
//do something } }