cocoa touch - NSDataDetector with NSTextCheckingTypeLink detects URL and PhoneNumbers! -


i trying url simple nsstring sentence. use nsdatadetector in following code:

nsstring *string = @"this sample of http://abc.com/efg.php?efaei687e3esa sentence url within , number 097843.";  nsdatadetector *linkdetector = [nsdatadetector datadetectorwithtypes:nstextcheckingtypelink error:nil];  nsarray *matches = [linkdetector matchesinstring:string options:0 range:nsmakerange(0, [string length])];  (nstextcheckingresult *match in matches) {    if ([match resulttype] == nstextcheckingtypelink) {     nsstring *matchingstring = [match description];     nslog(@"found url: %@", matchingstring);   } } 

the result finds url , number. number detected phone-number:

found url: http://abc.com/efg.php?efaei687e3esa found url: tel:097843 

is bug? tell me how url without telephone number?

nsdatadetector detects telephone numbers links because on phone, can tap them if link in order initiate phone call (or tap , hold initiate text message, etc). believe current locale (ie, nslocale) determines whether string of numbers looks phone number or not. example, in united states, take @ least 7 digits recognized phone number, since numbers in of general form: \d{3}-\d{4}.

as recognizing telephone link versus link, it's not idea check http:// @ beginning of url. simple example suffices: if it's https:// link? code breaks.

the better way check this:

nsarray *matches = [linkdetector matchesinstring:string options:0 range:nsmakerange(0, [string length])];  (nstextcheckingresult *match in matches) {   nsurl *url = [match url];   if ([[url scheme] isequal:@"tel"]) {     nslog(@"found telephone url: %@", url);   } else {     nslog(@"found regular url: %@", url);   } } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -