Skip to content

Commit 0b8edd8

Browse files
Updating foundational guide
1 parent a51d264 commit 0b8edd8

1 file changed

Lines changed: 43 additions & 54 deletions

File tree

programming/objectivec-swift/foundational-guide.md

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ Dynamsoft Barcode Reader needs a valid license to work.
9898
>
9999
>1.
100100
```objc
101+
#import "ViewController.h"
101102
#import <DynamsoftCaptureVisionBundle/DynamsoftCaptureVisionBundle.h>
102-
@interface ViewController () <DSLicenseVerificationListener>
103+
@interface ViewController ()<DSLicenseVerificationListener>
104+
@end
103105
```
104106
2.
105107
```swift
@@ -115,14 +117,16 @@ Dynamsoft Barcode Reader needs a valid license to work.
115117
>
116118
>1.
117119
```objc
120+
@implementation ViewController
118121
- (void)setLicense {
119122
[DSLicenseManager initLicense:@"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" verificationDelegate:self];
120123
}
121124
- (void)onLicenseVerified:(BOOL)isSuccess error:(nullable NSError *)error {
122125
if (!isSuccess && error != nil) {
123-
NSLog(@"error: %@", error);
126+
NSLog(@"error: %@", error);
124127
}
125128
}
129+
@end
126130
```
127131
2.
128132
```swift
@@ -147,56 +151,41 @@ Dynamsoft Barcode Reader needs a valid license to work.
147151
148152
### Step 4: Configure the Camera Enhancer
149153

150-
1. Import all the headers that you will need in the `ViewController` file.
151-
152-
<div class="sample-code-prefix"></div>
153-
>- Objective-C
154-
>- Swift
155-
>
156-
>1.
157-
```objc
158-
#import <DynamsoftCaptureVisionBundle/DynamsoftCaptureVisionBundle.h>
159-
```
160-
2.
161-
```swift
162-
import DynamsoftCaptureVisionBundle
163-
```
164-
165-
2. Initialize `CameraEnhancer` and `CameraView` and add configurations for the `CameraEnhancer`.
154+
Initialize `CameraEnhancer` and `CameraView` and add configurations for the `CameraEnhancer`.
166155

167-
<div class="sample-code-prefix"></div>
168-
>- Objective-C
169-
>- Swift
170-
>
171-
>1.
172-
```objc
173-
@interface ViewController () <DSLicenseVerificationListener>
174-
@property (nonatomic, strong) DSCameraView *cameraView;
175-
@property (nonatomic, strong) DSCameraEnhancer *dce;
176-
@end
177-
...
178-
@implementation ViewController
179-
- (void)setUpCamera {
180-
self.cameraView = [[DSCameraView alloc] initWithFrame:self.view.bounds];
181-
self.cameraView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
182-
[self.view insertSubview:self.cameraView atIndex:0];
183-
self.dce = [[DSCameraEnhancer alloc] init];
184-
self.dce.cameraView = self.cameraView;
185-
}
186-
...
187-
```
188-
2.
189-
```swift
190-
var cameraView:CameraView!
191-
let dce = CameraEnhancer()
192-
...
193-
func setUpCamera() {
194-
cameraView = .init(frame: view.bounds)
195-
cameraView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
196-
view.insertSubview(cameraView, at: 0)
197-
dce.cameraView = cameraView
198-
}
199-
```
156+
<div class="sample-code-prefix"></div>
157+
>- Objective-C
158+
>- Swift
159+
>
160+
>1.
161+
```objc
162+
@interface ViewController () <DSLicenseVerificationListener>
163+
@property (nonatomic, strong) DSCameraView *cameraView;
164+
@property (nonatomic, strong) DSCameraEnhancer *dce;
165+
@end
166+
...
167+
@implementation ViewController
168+
- (void)setUpCamera {
169+
self.cameraView = [[DSCameraView alloc] initWithFrame:self.view.bounds];
170+
self.cameraView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
171+
[self.view insertSubview:self.cameraView atIndex:0];
172+
self.dce = [[DSCameraEnhancer alloc] init];
173+
self.dce.cameraView = self.cameraView;
174+
}
175+
...
176+
```
177+
2.
178+
```swift
179+
var cameraView:CameraView!
180+
let dce = CameraEnhancer()
181+
...
182+
func setUpCamera() {
183+
cameraView = .init(frame: view.bounds)
184+
cameraView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
185+
view.insertSubview(cameraView, at: 0)
186+
dce.cameraView = cameraView
187+
}
188+
```
200189

201190
### Step 5: Configure the Barcode Decoding Task via CaptureVisionRouter
202191

@@ -296,10 +285,10 @@ Dynamsoft Barcode Reader needs a valid license to work.
296285
}
297286
}
298287
}
299-
private func showResult(_ title: String, _ message: String, completion: @escaping () -> Void) {
288+
private func showResult(_ title: String, _ message: String?, completion: (() -> Void)? = nil) {
300289
DispatchQueue.main.async {
301290
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
302-
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in completion() }))
291+
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in completion?() }))
303292
self.present(alert, animated: true, completion: nil)
304293
}
305294
}
@@ -411,7 +400,7 @@ Starting from v11.2.1000, Dynamsoft Barcode Reader integrates deep learning mode
411400
>1.
412401
```objc
413402
- (void)dealloc {
414-
[CaptureVisionRouter clearDLModelBuffers];
403+
[DSCaptureVisionRouter clearDLModelBuffers];
415404
}
416405
```
417406
2.

0 commit comments

Comments
 (0)