Open a mini-program via a promotional QR code
For promotional purposes, you can create a QR code for your mini-program on Mini Program Platform and hand it out to consumers. However, the content of the promotional QR code is an encoded URL, which cannot be used to open a mini-program directly.
To allow consumers to open a mini-program via a promotional QR code, Mini Program Platform provides the following two APIs for iOS IAPMiniProgram SDK:
- canDecodeUrlContent: Call this API to verify if the QR code can be decoded.
- decodeUrlContent: Call this API to decode the QR code.
Procedures
Step 1: Verify if the QR code can be decoded
To verify if the QR code can be decoded by iOS IAPMiniProgram SDK and used to open a mini-program, you need to integrate the canDecodeUrl API.
For more information, see canDecodeUrlContent.
Step 2: Decode the QR code
For QR codes that can be decoded, you need to integrate the decodeUrlContent API for decoding.
For more information, see decodeUrlContent.
Step 3: Open the mini-program
After receiving the decoded URL, call the openAppWithUrl API to open the mini-program.
For more information, see openAppWithUrl.
Sample
The following sample shows how the APIs above cooperate to decode a promotional QR code and open a mini-program.
import ACGriverCore
// the scanning result of the QR Code
let scanResult: String = ...
// test whether the URL can be decoded
if (GRVURLContentDecoder.canDecodeURLContent(scanResult)) {
GRVURLContentDecoder.decodeURLContent(scanResult) { (response) in
// use the decoded URL to open a mini program
if response.success, let decodedURL = response.decodedURL {
GRVAppContainerLaunch.sharedInstance().openApp(withUrl: decodedURL, extraParams: [:])
} else {
print(response.errorMessage ?? "")
}
}
}