SAP

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Use the Barcode Scanner API

Implement a small search logic which will look for the correct products depending on the barcode the app scans.

Overview

You will learn

  • ✔How to add a FUISearchBar and implement item searching on an UITableViewController
  • ✔How to add the FUIBarcodeScanner to the FUISearchBar and search in a UITableViewController with the scan result of the FUIBarcodeScanner.
Sandeep T D S S Sandeep T D S January 9, 2023
Created on January 9, 2023
Contributors

More from Sandeep T D S

See all 10 tutorials by Sandeep T D S →

Prerequisites

  • Development environment: Apple Mac running macOS Catalina or higher with Xcode 11 or higher
  • SAP BTP SDK for iOS: Version 5.0
  • Set Up the SAP BTP SDK for iOS

Steps

Details

You will learn

  • How to add a FUISearchBar and implement item searching on an UITableViewController
  • How to add the FUIBarcodeScanner to the FUISearchBar and search in a UITableViewController with the scan result of the FUIBarcodeScanner.

Step 1 Replace the generated app UI with your own
—

This tutorial uses the generated app out of the Set Up the SAP BTP SDK for iOS tutorial group.

Please open up the TutorialApp created in the above mentioned tutorial group. The app contains a Master-Detail View which has to be removed to add a UITableViewController displaying a list of products.

Open the Main.storyboard in Interface Builder to delete the existing generated UI. Select all View Controllers and delete them.

alterui
alterui

Next add a new UITableViewController to the storyboard from the Object Library. This will later display a list of products and implement the FUISearchBar and FUIBarcodeScanner.

alterui
alterui

To give the app the correct entry point it is necessary to make the newly added UITableViewController an initial View Controller. In the Main.storyboard select the UITableViewController and go to the Attributes Inspector on the right sidebar. Check the box Is Initial View Controller, an arrow should appear next to the View Controller.

alterui
alterui

To actually work with the View Controller a subclass of UITableViewController must be created and connected to the UI representative in Interface Builder. Select the top-level group in the Project navigator on the left-hand side. Choose File -> New -> File… or simply right-click to open the context menu and click on New File…. In the upcoming dialogue make sure that Subclass of: is UITableViewController and choose ProductTableViewController as class name.

Please don’t forget to check that Swift is selected as language before creating the class.

alterui
alterui

Go back to the Main.storyboard and select the UITableViewController. Backing up a View Controller in storyboard is simple, select the view controller and click on the Identity Inspector icon on the right-hand side. Under Custom Class enter the ProductTableViewController and hit return. The name in the hierarchy stack should change now and display the name of the added class.

alterui
alterui

All the setup is done now for a new and fresh UI, the last step would be changing the ApplicationUIManager.swift code to load the new View Controller instead of the old Master-Detail View ones. The ApplicationUIManager is a class responsible for managing initial and Splash screens for the Onboarding UI flow.

In Xcode, open ApplicationUIManager.swift and locate the method showApplicationScreen(completionHandler: @escaping (Error?) -> Void).

Hint: You can use the Open Quickly feature of Xcode to search for the ApplicationUIManager class with Command + Shift + O. Once you’ve opened the file, you can quickly jump to the showApplicationScreen(completionHandler: @escaping (Error?) -> Void) function by using the jump bar at the top of the editor area pane.

alterui
alterui

Currently the code will try instantiating the first screen of the Master-Detail View. We deleted those so we have to make sure that our ProductTableViewController will be instantiated instead.

Replace the following code inside the showApplicationScreen(completionHandler:) method:

Swift
  let appDelegate = (UIApplication.shared.delegate as! AppDelegate)
  let splitViewController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "MainSplitViewController") as! UISplitViewController
  splitViewController.delegate = appDelegate
  splitViewController.modalPresentationStyle = .currentContext
  splitViewController.preferredDisplayMode = .allVisible
  appViewController = splitViewController

with:

Swift
  let productTableViewController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController() as! ProductTableViewController
  appViewController = productTableViewController

Instead of instantiating the MainSplitViewController the UIStoryboard will instantiate the initial View Controller and cast it to the ProductTableViewController.

If you run the app now, you should see a screen with an empty UITableView.

The screen will be visible after you completed the Onboarding flow.

Step 2 Load products from the OData Service
+
Step 3 Populate the UITableView with data
+
Step 4 Add the FUISearchBar & FUIBarcodeScanner to the ProductTableViewController
+
Step 5 Implement the search result handling and update of the UITableViewController
+
Step 6 Ask for permission to use the Camera
+
Step 7 Embed the ProductTableViewController in a UINavigationController
+
Step 8 Implement the FUIBarcodeScanViewController for more flexible use
+
Step 9 Handle the Scan Result
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 9
1. Replace the generated app UI with your own 2. Load products from the OData Service 3. Populate the UITableView with data 4. Add the FUISearchBar & FUIBarcodeScanner to the ProductTableViewController 5. Implement the search result handling and update of the UITableViewController 6. Ask for permission to use the Camera 7. Embed the ProductTableViewController in a UINavigationController 8. Implement the FUIBarcodeScanViewController for more flexible use 9. Handle the Scan Result