How to Upgrade
From v3.2.x to v3.4.x
Update the Libraries
There are 2 ways in which you can include the DynamsoftMRZScannerBundle library in your app:
Option 1: Add the xcframeworks via Swift Package Manager
-
In your Xcode project, go to File –> AddPackages.
-
In the top-right section of the window, search “https://github.com/Dynamsoft/mrz-scanner-spm”
-
Select
mrz-scanner-spm, chooseUp to Next Major Version, then click Add Package. -
Check all the xcframeworks and add.
Option 2: Add the Frameworks via CocoaPods
-
Add the frameworks in your Podfile, replace
TargetNamewith your real target name.target 'ScanMRZ' do use_frameworks! pod 'DynamsoftMRZScannerBundle','{version-number}' endPlease view user guide for the correct version number.
-
Execute the pod command to install the frameworks and generate workspace([TargetName].xcworkspace):
pod install
Handle Breaking Changes
MRZScanResult.data Is Now Nullable
The data property on MRZScanResult is now declared nullable. In Swift this becomes a compile error if you access it directly without unwrapping; in Objective-C it generates a nullability warning.
- Objective-C
- Swift
- ```objc // Before NSString *firstName = result.data.firstName;
// After if (result.data != nil) { NSString *firstName = result.data.firstName; }
2.
```swift
// Before
let firstName = result.data.firstName
// After
guard let data = result.data else { return }
let firstName = data.firstName
errorMessage Renamed to errorString
The errorMessage property on MRZScanResult has been renamed to errorString. Update any references in your code:
- Objective-C
- Swift
- ```objc // Before NSLog(@”%@”, result.errorMessage);
// After NSLog(@”%@”, result.errorString);
2.
```swift
// Before
print(result.errorMessage)
// After
print(result.errorString)
Adopt the New Image Capture APIs
v3.4.x adds the ability to retrieve captured images alongside the parsed MRZ data. Three types of images are available via MRZScanResult:
- Document image — a cropped, perspective-corrected image of the document. Enabled by default.
- Portrait image — the portrait extracted from the document. Enabled by default.
- Original image — the raw full-frame camera capture. Disabled by default.
Control which images are returned using the new MRZScannerConfig properties:
- Objective-C
- Swift
DSMRZScannerConfig *config = [[DSMRZScannerConfig alloc] init]; config.returnDocumentImage = YES; // default: YES config.returnPortraitImage = YES; // default: YES config.returnOriginalImage = NO; // default: NO — opt in to enablelet config = MRZScannerConfig() config.returnDocumentImage = true // default: true config.returnPortraitImage = true // default: true config.returnOriginalImage = false // default: false — opt in to enable
Retrieve the images from the scan result:
- Objective-C
- Swift
- ```objc DSImageData *portrait = [result getPortraitImage]; DSImageData *docImage = [result getDocumentImage:DSDocumentSideMRZ]; DSImageData *original = [result getOriginalImage:DSDocumentSideMRZ];
// For two-sided ID cards, also retrieve the opposite side: DSImageData *opposite = [result getDocumentImage:DSDocumentSideOpposite];
2.
```swift
let portrait = result.getPortraitImage()
let docImage = result.getDocumentImage(.mrz)
let original = result.getOriginalImage(.mrz)
// For two-sided ID cards, also retrieve the opposite side:
let opposite = result.getDocumentImage(.opposite)
All three methods return
nilif the corresponding return flag is disabled or the image was not captured.getDocumentImage(.opposite)andgetOriginalImage(.opposite)also returnnilfor single-sided documents such as passports.
From v2 to v3
Update the Libraries
There are 2 ways in which you can include the DynamsoftMRZScannerBundle library in your app:
Option 1: Add the xcframeworks via Swift Package Manager
-
In your Xcode project, go to File –> AddPackages.
-
In the top-right section of the window, search “https://github.com/Dynamsoft/mrz-scanner-spm”
-
Select
mrz-scanner-spm, chooseUp to Next Major Version, then click Add Package. -
Check all the xcframeworks and add.
Option 2: Add the Frameworks via CocoaPods
-
Add the frameworks in your Podfile, replace
TargetNamewith your real target name.target 'ScanMRZ' do use_frameworks! pod 'DynamsoftMRZScannerBundle','{version-number}' endPlease view user guide for the correct version number.
-
Execute the pod command to install the frameworks and generate workspace([TargetName].xcworkspace):
pod install