CodeService

IAPMiniProgram SDK calls the CodeService SPI to provide QR code or bar code.

scan

Method signature

Call the scan method to launch the QR code or bar code scanner, and return the code.

copy
func scan(
    with option: IAPWalletScannerOption,
    in context: IAPWalletAPIContext? = nil,
    callback: @escaping (IAPWalletScannerResult) -> Void
)

Request parameters

Field

Data type

Description

Required

option

IAPWalletScannerOption

The properties that a wallet scanner supports, including compatibility for QR code and barcode, and so on.

When this parameter is not specified, the default values of this parameter are used.

Yes

context

IAPWalletAPIContext

A context object, which carries the mini program runtime metadata.

No

callback

Callback (For details, see the following section)

The callback that is executed when request processing is completed.

Yes

Callback

Field

Data type

Description

Required

result

IAPWalletScannerResult

The result of the scan request.

Yes

Response parameters

N/A

Error codes

Error code

Error message

1000

ERROR_CODE_UNKNOWN_ERROR

Unknown error

1001

ERROR_CODE_USER_CANCEL

The user cancels the operation.

1002

ERROR_CODE_APP_SERVICE_ERROR

The app service is wrong.

1003

ERROR_CODE_TIMEOUT

Timeout

2001

ERROR_CODE_AUTH_PENDING_AGREEMENT

Authorization is not finished or is pending.

1005

ERROR_CODE_SYSTEM_ERROR

System error

Samples

The following samples show how to call the scan method to launch the QR code or bar code scanner and return the code.

Swift

copy
final class CodeService: IAPWalletCodeServiceSignature {
    override func scan(
        with option: IAPWalletScannerOption,
        in context: IAPWalletAPIContext? = nil,
        callback: @escaping (IAPWalletScannerResult) -> Void
    ) {
        // to scan code
        let scanResult = IAPWalletScannerResult(code: "CODE_VALUE")
        callback(scanResult)
    }
}