Detecting flight info via NSDataDetector's NSTextCheckingTypeTransitInformation is not ever matching anything

590 Views Asked by At

Has anyone had any luck using NSDataDetector on iOS to match flight information? It looks really amazingly powerful, except I can't get it to work at all.

Here's what I'm trying:

NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:(NSTextCheckingTypes)NSTextCheckingTypeTransitInformation error:&error];

[detector enumerateMatchesInString:string
                           options:0
                             range:NSMakeRange(0, [string length])
                        usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {

                            NSLog(@"Detected: %@, %@", result, [result URL]);
}

I'm trying this on a variety of strings, including the body of every calendar entry I could find in my calendar that had flight info in it.

Examples:

  • "UA460 SFO to YVR [Flight] 6/12/2013 United Airlines(UA) #460 dep SFO 7:57pm PDT arr YVR 10:14pm PDT; Ticket #0162360127882, Ticket #0162360127883; conf #K5XBXY; Note:, Seats:---/30A , Seats:---/30B "
  • "Pick up Laura at Airport UA 1255"
  • "Lufthansa 1128 Business (C) | Seat 07F Frankfurt Barcelona 2 h 0 m 679miles FRA 1:15pm BCN 3:15pm , Arrives on Fri Oct/5/2012
    Lufthansa 1128 Business (C) | Seat 07F | Confirm or change seats with the airline*"

But none of these match. If I change data detector types to include NSTextCheckingTypePhoneNumber or NSTextCheckingTypeLink, those match great. But I can't get flight data.

Any one have any luck with this?

2

There are 2 best solutions below

0
Thomas Deniau On

Flight numbers are detected on OS X, but not on iOS. Please file a bug with Apple to either get the documentation updated, or to get support for this on iOS.

0
Weiyan Lin On
    NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:(NSTextCheckingTypes)NSTextCheckingTypeTransitInformation error:nil];
    NSString *result = @"Pick up Laura at Airport UA 1255";
    [detector enumerateMatchesInString:result options:0 range:NSMakeRange(0, [result length]) usingBlock:^(NSTextCheckingResult * _Nullable result, NSMatchingFlags flags, BOOL * _Nonnull stop) {
        NSLog(@"%@ %@",result, [result components]);
    }];


2016-05-20 11:49:29.912 detectTest[20894:4085484] <NSTransitInformationCheckingResult: 0x7fcc92019f30>{25, 7} {
    Flight = 1255;
}

the only difference is flight info stored in [result components] rather than [result URL]