Skip to content

Commit e1e0079

Browse files
update to internal commit 8fe76bbc
1 parent be3417e commit e1e0079

File tree

1 file changed

+89
-89
lines changed

1 file changed

+89
-89
lines changed

programming/objectivec-swift/user-guide.md

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -218,100 +218,100 @@ Now that the license is configured and the license has been set, it is time to i
218218

219219
Each result comes with a `DSResultStatus` that can be one of *finished*, *canceled*, or *exception*. The first, *finished*, indicates that the result has been decoded and is available - while *canceled* indicates that the operation has been halted. If *exception* is the result status, then that means that an error has occurred during the barcode detection process. So let us now continue the code of the `buttonTapped` method from step 3:
220220

221-
<div class="sample-code-prefix"></div>
222-
>- Objective-C
223-
>- Swift
224-
>
225-
>1.
226-
```objc
227-
/* CONTINUATION OF CODE FROM STEP 3 */
228-
- (void)buttonTapped {
229-
DSBarcodeScannerViewController *vc = [[DSBarcodeScannerViewController alloc] init];
230-
DSBarcodeScannerConfig *config = [[DSBarcodeScannerConfig alloc] init];
231-
config.license = @"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
232-
// some other settings
233-
vc.config = config;
234-
__weak typeof(self) weakSelf = self;
235-
vc.onScannedResult = ^(DSBarcodeScanResult *result) {
236-
switch (result.resultStatus) {
237-
case DSResultStatusFinished: {
238-
dispatch_async(dispatch_get_main_queue(), ^{
239-
NSString *format = result.barcodes.firstObject.formatString ?: @"";
240-
NSString *text = result.barcodes.firstObject.text ?: @"";
241-
weakSelf.label.text = [NSString stringWithFormat:@"Result:\nFormat: %@\nText: %@", format, text];
242-
});
243-
break;
244-
}
245-
case DSResultStatusCanceled: {
246-
dispatch_async(dispatch_get_main_queue(), ^{
247-
weakSelf.label.text = @"Scan canceled";
248-
});
249-
break;
250-
}
251-
case DSResultStatusException: {
252-
dispatch_async(dispatch_get_main_queue(), ^{
253-
weakSelf.label.text = result.errorString;
254-
});
255-
break;
256-
}
257-
default:
258-
break;
221+
<div class="sample-code-prefix"></div>
222+
>- Objective-C
223+
>- Swift
224+
>
225+
>1.
226+
```objc
227+
/* CONTINUATION OF CODE FROM STEP 3 */
228+
- (void)buttonTapped {
229+
DSBarcodeScannerViewController *vc = [[DSBarcodeScannerViewController alloc] init];
230+
DSBarcodeScannerConfig *config = [[DSBarcodeScannerConfig alloc] init];
231+
config.license = @"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
232+
// some other settings
233+
vc.config = config;
234+
__weak typeof(self) weakSelf = self;
235+
vc.onScannedResult = ^(DSBarcodeScanResult *result) {
236+
switch (result.resultStatus) {
237+
case DSResultStatusFinished: {
238+
dispatch_async(dispatch_get_main_queue(), ^{
239+
NSString *format = result.barcodes.firstObject.formatString ?: @"";
240+
NSString *text = result.barcodes.firstObject.text ?: @"";
241+
weakSelf.label.text = [NSString stringWithFormat:@"Result:\nFormat: %@\nText: %@", format, text];
242+
});
243+
break;
259244
}
260-
dispatch_async(dispatch_get_main_queue(), ^{
261-
[weakSelf.navigationController popViewControllerAnimated:YES];
262-
});
263-
};
264-
dispatch_async(dispatch_get_main_queue(), ^{
265-
weakSelf.navigationController.navigationBar.hidden = YES;
266-
[weakSelf.navigationController pushViewController:vc animated:YES];
267-
});
268-
}
269-
```
270-
2.
271-
```swift
272-
class ViewController: UIViewController {
273-
/* CONTINUATION OF CODE FROM STEP 3 */
274-
@objc func buttonTapped() {
275-
let vc = BarcodeScannerViewController()
276-
let config = BarcodeScannerConfig()
277-
config.license = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"
278-
// some other settings
279-
vc.config = config
280-
vc.onScannedResult = { [weak self] result in
281-
guard let self = self else { return }
282-
switch result.resultStatus {
283-
/* if the result is valid, display it in the label */
284-
case .finished:
285-
DispatchQueue.main.async {
286-
let format = result.barcodes?.first?.formatString ?? ""
287-
self.label.text = "Result:\nFormat: " + (format) + "\n" + "Text: " + (result.barcodes?.first?.text ?? "")
288-
}
289-
/* if the scan operation is canceled by the user */
290-
case .canceled:
291-
DispatchQueue.main.async {
292-
self.label.text = "Scan canceled"
293-
}
294-
/* if an error occurs during capture, display the error string in the label */
295-
case .exception:
296-
DispatchQueue.main.async {
297-
self.label.text = result.errorString
298-
}
299-
@unknown default:
300-
break
301-
}
302-
/* return back to the home page to display the result/cancel message/error string */
303-
DispatchQueue.main.async {
304-
self.navigationController?.popViewController(animated: true)
305-
}
245+
case DSResultStatusCanceled: {
246+
dispatch_async(dispatch_get_main_queue(), ^{
247+
weakSelf.label.text = @"Scan canceled";
248+
});
249+
break;
306250
}
307-
/* when the button is clicked, hide the navigation bar and push the newly created BarcodeScannerViewController to the main view */
251+
case DSResultStatusException: {
252+
dispatch_async(dispatch_get_main_queue(), ^{
253+
weakSelf.label.text = result.errorString;
254+
});
255+
break;
256+
}
257+
default:
258+
break;
259+
}
260+
dispatch_async(dispatch_get_main_queue(), ^{
261+
[weakSelf.navigationController popViewControllerAnimated:YES];
262+
});
263+
};
264+
dispatch_async(dispatch_get_main_queue(), ^{
265+
weakSelf.navigationController.navigationBar.hidden = YES;
266+
[weakSelf.navigationController pushViewController:vc animated:YES];
267+
});
268+
}
269+
```
270+
2.
271+
```swift
272+
class ViewController: UIViewController {
273+
/* CONTINUATION OF CODE FROM STEP 3 */
274+
@objc func buttonTapped() {
275+
let vc = BarcodeScannerViewController()
276+
let config = BarcodeScannerConfig()
277+
config.license = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"
278+
// some other settings
279+
vc.config = config
280+
vc.onScannedResult = { [weak self] result in
281+
guard let self = self else { return }
282+
switch result.resultStatus {
283+
/* if the result is valid, display it in the label */
284+
case .finished:
285+
DispatchQueue.main.async {
286+
let format = result.barcodes?.first?.formatString ?? ""
287+
self.label.text = "Result:\nFormat: " + (format) + "\n" + "Text: " + (result.barcodes?.first?.text ?? "")
288+
}
289+
/* if the scan operation is canceled by the user */
290+
case .canceled:
291+
DispatchQueue.main.async {
292+
self.label.text = "Scan canceled"
293+
}
294+
/* if an error occurs during capture, display the error string in the label */
295+
case .exception:
296+
DispatchQueue.main.async {
297+
self.label.text = result.errorString
298+
}
299+
@unknown default:
300+
break
301+
}
302+
/* return back to the home page to display the result/cancel message/error string */
308303
DispatchQueue.main.async {
309-
self.navigationController?.navigationBar.isHidden = true
310-
self.navigationController?.pushViewController(vc, animated: true)
304+
self.navigationController?.popViewController(animated: true)
311305
}
312-
}
306+
}
307+
/* when the button is clicked, hide the navigation bar and push the newly created BarcodeScannerViewController to the main view */
308+
DispatchQueue.main.async {
309+
self.navigationController?.navigationBar.isHidden = true
310+
self.navigationController?.pushViewController(vc, animated: true)
311+
}
313312
}
314-
```
313+
}
314+
```
315315

316316
## Step 5: Configure the Barcode Scanner (optional)
317317

0 commit comments

Comments
 (0)