All Products
Search
Document Center

Mobile Platform as a Service:Quick Start

Last Updated:May 25, 2021

The Scan SDK is currently used by Alipay to scan QR codes, barcodes, and other functions. This topic describes how to use the Scan SDK.

Prerequisites

You have added the Scan SDK to the project according to your access method. For more information, see the following content: Connect to mPaaS based on an existing project and CocoaPods.

Add the SDK

Use CocoaPods plugin to add the Scan SDK. Complete the following steps:

  1. In the Podfile file, use mPaaS_pod "mPaaS_ScanCode" to add mobile gateway component dependencies.
  2. In the terminal, run pod install to complete access.

Using SDK version 10.1.68.17 and later

Procedure

  1. Trigger the default scan page and process the scan results.

    1. @interface MPScanDemoVC()<TBScanViewControllerDelegate>
    2. @property(nonatomic, strong) TBScanViewController *scanVC;
    3. @end
    4. - (void)defaultScan {
    5. TBScanViewController *vc = [[MPScanCodeAdapterInterface sharedInstance] createDefaultScanPageWithallback:^(id _Nonnull result, BOOL keepAlive) {
    6. // Process scan results.
    7. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:result[@"resp_result"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    8. alert.tag = 1999;
    9. [alert show];
    10. }];
    11. [self.navigationController pushViewController:vc animated:YES];
    12. self.scanVC = vc;
    13. }
  2. Continue to scan the code.

    1. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    2. // Continue to scan the code.
    3. [self.scanVC resumeScan];
    4. }

Use SDK version 10.1.68.17 and earlier

This topic describes how to use the Scan SDK in baseline version 10.1.68.17 and earlier based on the official demo of Scan.

Procedure

  1. Trigger the scan page.
    1. @interface MPScanDemoVC()<TBScanViewControllerDelegate>
    2. @property(nonatomic, strong) TBScanViewController *scanVC;
    3. @end
    4. - (void)startDefauleScanViewController
    5. {
    6. TBScanViewController *vc = [[TBScanViewController alloc] init];
    7. vc.scanType = ScanType_All_Code;
    8. vc.delegate = self;
    9. [self.navigationController pushViewController:vc animated:YES];
    10. self.scanVC = vc;
    11. }
  2. Process scan results.

    1. #pragma mark Process scan results.
    2. -(void)didFind:(NSArray<TBScanResult*>*)resultArray
    3. {
    4. if([resultArray count] > 0) {
    5. TBScanResult *result = resultArray.firstObject;
    6. NSString* content = result.data;
    7. dispatch_async(dispatch_get_main_queue(), ^{
    8. // Note: The scan results are in the child thread. If there are UI-related operations, switch to the main thread.
    9. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:content delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    10. [alert show];
    11. });
    12. }
    13. }
  3. Continue to scan the code.
    1. #pragma mark alert
    2. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    3. [self.scanVC resumeScan];
    4. }