Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect links within an NSString that have spaces in them with NSDataDetector?

Tags:

First off, I have no control over the text I am getting. Just wanted to put that out there so you know that I can't change the links.

The text I am trying to find links in using NSDataDetector contains the following:

<h1>My main item</h1>
<img src="http://www.blah.com/My First Image Here.jpg">
<h2>Some extra data</h2>

The detection code I am using is this, but it will not find this link:

NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [linkDetector matchesInString:myHTML options:0 range:NSMakeRange(0, [myHTML length])];

for (NSTextCheckingResult *match in matches) 
{
   if ([match resultType] == NSTextCheckingTypeLink)
   {
      NSURL *url = [match URL];
      // does some stuff
   }
}

Is this a bug with Apple's link detection here, where it can't detect links with spaces, or am I doing something wrong?

Does anyone have a more reliable way to detect links regardless of whether they have spaces or special characters or whatever in them?

like image 552
Ethan Allen Avatar asked Jun 09 '15 19:06

Ethan Allen


1 Answers

I just got this response from Apple for a bug I filed on this:

We believe this issue has been addressed in the latest iOS 9 beta. This is a pre-release iOS 9 update.

Please refer to the release notes for complete installation instructions.

Please test with this release. If you still have issues, please provide any relevant logs or information that could help us investigate.

iOS 9 https://developer.apple.com/ios/download/

I will test and let you all know if this is fixed with iOS 9.

like image 66
Ethan Allen Avatar answered Oct 12 '22 09:10

Ethan Allen