@@ -151,20 +151,17 @@ - (NSMutableAttributedString *)attributedString {
151151 startOffset += width;
152152 }
153153
154- // if links are supported, create links in all the locations we found last time we scanned for
155- // links
156- if (IS_IOS_OR_NEWER (iOS_7_0)) {
157- for (NSValue *value in _lastLinkRanges) {
158- NSRange range = value.rangeValue ;
154+ // create links in all the locations we found last time we scanned for links
155+ for (NSValue *value in _lastLinkRanges) {
156+ NSRange range = value.rangeValue ;
159157
160- if (range.location + range.length <= attributedString.string .length ) {
161- NSString *urlString = [attributedString.string substringWithRange: range];
162- NSURL *url = [NSURL URLWithString: urlString];
158+ if (range.location + range.length <= attributedString.string .length ) {
159+ NSString *urlString = [attributedString.string substringWithRange: range];
160+ NSURL *url = [NSURL URLWithString: urlString];
163161
164- // if NSURL thinks this is a valid url,
165- if (url) {
166- [attributedString addAttribute: NSLinkAttributeName value: url range: range];
167- }
162+ // if NSURL thinks this is a valid url, it’s good enough for us
163+ if (url) {
164+ [attributedString addAttribute: NSLinkAttributeName value: url range: range];
168165 }
169166 }
170167 }
@@ -173,16 +170,11 @@ - (NSMutableAttributedString *)attributedString {
173170}
174171
175172- (void )detectLinksForAttributedString : (NSMutableAttributedString *)attributedString {
176- // links are only natively supported as of iOS 7, i probably won’t bother to add all the support
177- // needed for links on iOS 6
178- if (!IS_IOS_OR_NEWER (iOS_7_0)) {
179- return ;
180- }
181-
182173 static dispatch_once_t onceToken;
183174 dispatch_once (&onceToken, ^{
184175 _lastLinkRanges = [NSMutableSet set ];
185176
177+ // not exactly sure why a data detector would fail to init…
186178 NSError *error = nil ;
187179 _linkDataDetector = [[NSDataDetector alloc ] initWithTypes: NSTextCheckingTypeLink error: &error];
188180 NSAssert (!error, @" %@ " , error.description);
@@ -224,7 +216,6 @@ - (void)detectLinksForAttributedString:(NSMutableAttributedString *)attributedSt
224216 if (![_lastLinkRanges containsObject: value]) {
225217 NSRange range = value.rangeValue ;
226218 NSURL *url = [NSURL URLWithString: [attributedString.string substringWithRange: range]];
227- HBLogDebug (@" adding2 %@ = %@ " , url, NSStringFromRange (range));
228219 [attributedString addAttribute: NSLinkAttributeName value: url range: range];
229220 }
230221 }
0 commit comments