Search code examples
iosobjective-cnsdatadetectordatadetectortypes

NSDataDetector type NSTextCheckingTypeTransitInformation - is it available for iOS?


I use the following code, sending a recent UPS tracking number (string), to see if the NSDataDetector will detect the tracking number as a match for the NSTextCheckingTypeTransitInformation type. The method returns zero results. When I type this same tracking number into the Notes iOS app, it gives me the option to view the tracking link ("Track Shipment").

- (void)checkTrackingNumber:(NSString*)trackingNumber {

    NSError *error = nil;
    NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeTransitInformation error:&error];
    [detector enumerateMatchesInString:trackingNumber
                               options:0
                                 range:NSMakeRange(0, [trackingNumber length])
                            usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
                                // Do Something Here
                                NSLog(@"result.URL is: %@",result.URL);
                            }];
}

Is there some reason that the above code would not work in an iOS app for a valid tracking number?


Solution

  • it checks NSTextCheckingAirlineKey and NSTextCheckingFlightKey. information when you use NSTextCheckingTypeTransitInformation, it would not check UPS Tracking number