Skip to content

Commit

Permalink
Changed iOS date parsing for ID results
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Müller committed Jan 21, 2019
1 parent 000c309 commit 09dbb59
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions plugin/ios/ALPluginHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,6 @@ + (NSDictionary *)dictionaryForIDResult:(ALIDResult *)scanResult

NSString *imagePath = [self saveImageToFileSystem:scanResult.image compressionQuality:dividedCompRate];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy.MM.dd"];

if ([scanResult.result isKindOfClass:[ALMRZIdentification class]]) {
ALMRZIdentification *mrzIdentification = (ALMRZIdentification *)scanResult.result;

Expand All @@ -412,9 +409,6 @@ + (NSDictionary *)dictionaryForIDResult:(ALIDResult *)scanResult
if ([[scanResult.result documentType] isEqualToString:@"ID"] && [[scanResult.result issuingCountryCode] isEqualToString:@"D"]) {
[dictResult setValue:mrzIdentification.address forKey:@"address"];
}

NSString *expirationDateObject = [formatter stringFromDate:[scanResult.result expirationDateObject]];
[dictResult setValue:expirationDateObject forKey:@"expirationDateObject"];
} else {
dictResult = [[scanResult.result dictionaryWithValuesForKeys:@[@"documentNumber",
@"surNames",
Expand All @@ -426,18 +420,11 @@ + (NSDictionary *)dictionaryForIDResult:(ALIDResult *)scanResult
@"authority",
@"categories",
@"drivingLicenseString"]] mutableCopy];

// NSString *issuingDateObject = [formatter stringFromDate:[scanResult.result issuingDateObject]];
// [dictResult setValue:issuingDateObject forKey:@"issuingDateObject"];
}
// NSString *dayOfBirthDateObject = [formatter stringFromDate:[scanResult.result dayOfBirthDateObject]];
[dictResult setValue:[NSString stringWithFormat: @"%@",[scanResult.result dayOfBirthDateObject]] forKey:@"dayOfBirthObject"];

// NSString *expirationDateObject = [formatter stringFromDate:[scanResult.result expirationDateObject]];
[dictResult setValue:[NSString stringWithFormat: @"%@",[scanResult.result expirationDateObject]] forKey:@"expirationDateObject"];

[dictResult setValue:[NSString stringWithFormat: @"%@",[scanResult.result issuingDateObject]] forKey:@"issuingDateObject"];

[dictResult setValue:[ALPluginHelper stringForDate:[scanResult.result dayOfBirthDateObject]] forKey:@"dayOfBirthObject"];
[dictResult setValue:[ALPluginHelper stringForDate:[scanResult.result expirationDateObject]] forKey:@"expirationDateObject"];
[dictResult setValue:[ALPluginHelper stringForDate:[scanResult.result issuingDateObject]] forKey:@"issuingDateObject"];

[dictResult setValue:imagePath forKey:@"imagePath"];

Expand Down Expand Up @@ -543,4 +530,22 @@ + (NSDictionary *)dictionaryForTransformedImage:(UIImage *)transformedImage
return dictResult;
}

#pragma mark - Date Parsing Utils

+ (NSString *)stringForDate:(NSDate *)date {
if (!date) {
return nil;
}

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC+0:00"]];
[dateFormatter setDateFormat:@"EEE MMM d hh:mm:ss ZZZZ yyyy"];

//Date will be formatted to string - e.g.: "Fri Jan 11 12:00:00 GMT+0:00 1980"
NSString *dateString = [dateFormatter stringFromDate:date];

return dateString;
}


@end

0 comments on commit 09dbb59

Please sign in to comment.