NSDataDetector,字符串中检测URL

来源:互联网 发布:无锡亚信数据有限公司 编辑:程序博客网 时间:2024/06/05 15:06
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];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];
NSURL *url = [match URL];
    }
}
0 0
原创粉丝点击