This guide shows how to add the Code Scanner SDK to an iOS project that already uses CocoaPods and mPaaS. The SDK supports QR codes, barcodes, and multi-code detection.
Two integration paths are available — choose the one that matches your mPaaS baseline:
Baseline 10.1.68.17 or later — uses the
MPScanCodeAdapterInterfaceadapter API-
Earlier than 10.1.68.17 — uses
TBScanViewControllerdirectlyPrerequisites
Before you begin, ensure that you have:
An iOS project connected to mPaaS via CocoaPods. If not, see Connecting to mPaaS with an Existing Project and CocoaPods
Add the SDK
-
In your Podfile, add the Code Scanner dependency:
mPaaS_pod "mPaaS_ScanCode"
Run
pod installto install the SDK.
Use the SDK (10.1.68.17 or later)
The following steps use the adapter API introduced in baseline 10.1.68.17. Full working examples are in the official Code Scanner demo.
Multi-code detection is supported only in the standard interface.
-
Call the standard scan page and handle the result in the callback.
@interface MPScanDemoVC()<TBScanViewControllerDelegate> @property(nonatomic, strong) TBScanViewController *scanVC; @end - (void)defaultScan { TBScanViewController *vc = [[MPScanCodeAdapterInterface sharedInstance] createDefaultScanPageWithallback:^(id _Nonnull result, BOOL keepAlive) { 0000000000000000 // Process the scan result UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:result[@"resp_result"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; alert.tag = 1999; [alert show]; }]; [self.navigationController pushViewController:vc animated:YES]; self.scanVC = vc; } -
To let users scan again after viewing a result, call
resumeScanwhen they dismiss the alert.- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // Scan continuously [self.scanVC resumeScan]; }
Use the SDK (earlier than 10.1.68.17)
The following steps use TBScanViewController directly. Full working examples are in the official Code Scanner demo.
-
Initialize and push the scan view controller.
@interface MPScanDemoVC()<TBScanViewControllerDelegate> @property(nonatomic, strong) TBScanViewController *scanVC; @end - (void)startDefauleScanViewController { TBScanViewController *vc = [[TBScanViewController alloc] init]; vc.scanType = ScanType_All_Code; vc.delegate = self; [self.navigationController pushViewController:vc animated:YES]; self.scanVC = vc; } -
Implement the delegate method to receive results. The result is delivered on a background thread — switch to the main thread before updating the UI.
#pragma mark Process the scan result -(void)didFind:(NSArray<TBScanResult*>*)resultArray { if([resultArray count] > 0) { TBScanResult *result = resultArray.firstObject; NSString* content = result.data; dispatch_async(dispatch_get_main_queue(), ^{ // Note: The scan result is returned in a subthread. Switch to the main thread for UI-related operations. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:content delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; }); } } -
To let users scan again after viewing a result, call
resumeScanwhen they dismiss the alert.#pragma mark alert - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { [self.scanVC resumeScan]; }