Skip to main content

QR Code Plugin

The QR code plugin provides useful functions for QR code operations in your app, including methods to open the QR code scanner, display a QR code, and customize an icon and position marker color for the QR code.

The QR code scanner interface consists of 3 main features:

  • My QR code: To generate and display a QR code.
  • Select from album: To select a QR code image from the system album.
  • Turn on torch light: To toggle the device flashlight, automatically displayed when the surrounding brightness is low.
Image: Scanner interface

note

For iOS 14.0+ and Android 14+, when app access to the system album is restricted, only photos selected by the player will be shown when Select from album is clicked.

Album with limited photo access:
Image: Limited photo access

Prerequisites

  1. Integrate the Player Network SDK
2. iOS configurations
caution

For iOS on Unity, set up Game Center as an identity provider first before implementing the QR code plugin.

Add the following keys and values to your project's Info.plist file:

  • UISupportsRightToLeft: Enables right-to-left language support.

  • CFBundleAllowMixedLocalizations: Allows mixed localizations.

  • PHPhotoLibraryPreventAutomaticLimitedAccessAlert: Prevents the limited photos access alert.

  • NSPhotoLibraryUsageDescription: Describes why the app needs access to the photo library.

  • NSCameraUsageDescription: Describes why the app needs access to the camera.

      <plist version="1.0">
    <dict>
    <key>UISupportsRightToLeft</key>
    <true/>

    <key>CFBundleAllowMixedLocalizations</key>
    <true/>

    <key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
    <true/>

    <key>NSPhotoLibraryUsageDescription</key>
    <string>This app requires access to your photo library to upload and share your photos.</string>

    <key>NSCameraUsageDescription</key>
    <string>This app requires access to your camera to capture photos and videos for your profile and posts.</string>
    </dict>
    </plist>

Register Callbacks

Add the following observers to handle callbacks:

// Add callbacks
public void AddQRCodeObserver()
{
INTLAPI.AddQRCodeResultObserver(OnQRCodeResultEvent);
}

// Remove callbacks
public void RemoveQRCodeObserver()
{
INTLAPI.RemoveQRCodeResultObserver(OnQRCodeResultEvent);
}

// Process the INTLQRCodeResult callback
private void OnQRCodeResultEvent(INTLQRCodeResult qrCodeRet)
{
Debug.Log("OnQRCodeResultEvent");

string methodTag = "";

if (qrCodeRet.MethodId == (int)INTLMethodID.INTL_QRCODE_OPEN_SCANNER)
{
methodTag = "OpenQRScanner";
}
else if (qrCodeRet.MethodId == (int)INTLMethodID.INTL_QRCODE_SHOW)
{
methodTag = "ShowQRCode";
}
else if (qrCodeRet.MethodId == (int)INTLMethodID.INTL_QRCODE_SET_ICON)
{
methodTag = "SetIcon";
}
else if (qrCodeRet.MethodId == (int)INTLMethodID.INTL_QRCODE_SET_POSITION_MARKER_COLOR)
{
methodTag = "SetPositionMarkerColor";
}
}

OpenQRScanner

Opens the QR code scanner with the specified parameters.

  • qrCodeContent: JSON string for QR code generation, to be customized according to your requirements.
string qrCodeContent = "{\
\"deeplink\": \"https://example.com/path\", \
\"openid\": \"user-12345\", \
\"additionalKey1\": \"value1\"\
}";

INTLAPI.OpenQRScanner(qrCodeContent);

ShowQRCode

Displays the specified QR code content.

  • qrCodeContent: JSON string for QR code generation, to be customized according to your requirements.
string qrCodeContent = "{\
\"deeplink\": \"https://example.com/path\", \
\"openid\": \"user-12345\", \
\"additionalKey1\": \"value1\"\
}";

INTLAPI.ShowQRCode(qrCodeContent);
Image: Show QR Code

SetIcon

Sets an icon for the generated QR code.

  • imageURL: URL of the icon.
string imageURL = "https://example.com/icon.png";

INTLAPI.SetIcon(imageURL);
Image: Set Icon

SetPositionMarkerColor

Sets the position marker color for the QR code.

  • hexCode: Hexadecimal string representing the color of the position marker, such as #FF5733.
string hexCode = "#FF5733";

INTLAPI.SetPositionMarkerColor(hexCode);
Image: Set Position Marker Color