Quickstart

This topic introduces how to quickly set up the iOS IAPMiniProgram SDK and implement basic mini-program capabilities.

Before you begin

Before you get started, ensure you are familiar with the following things:

  • To run mini-programs, your device needs to be iOS 11 or later.
  • Xcode 14.0 or later is installed on your computer.
  • CocoaPods 1.10.0 or later is installed on your computer.

Get started

To get started with IAPMiniProgram SDK, perform the following actions:

Step 1: Download the configuration files

Log in to Mini Program Platform, go to the Apps page, and click Resource > iOS Resource to download the configuration file for the iOS SDK. A file named iapconnect_config_full is downloaded to your computer.

For more information about how to download app resources, see Download app resources.

Step 2: Add the configuration file

Move the iapconnect_config_full file into the root of your Xcode project. When a dialog box pops up, tick the checkboxes to add the file to all targets, such as MyCoolApp and MyCoolAppDev in the following screenshot.

image

To confirm that the configuration file is added to all intended targets, select the file in Xcode, and the Target Membership box on the right side shows the selected targets.

image

Step 3: Add dependencies

To add dependencies for the iOS IAPMiniProgram SDK, take the following steps:

  1. Update the .netrc file

For security reasons, Mini Program Platform uses a private CocoaPods source to distribute the pods. To gain access to the private source, you need to update your .netrc file which holds the required credentials. For more information about .netrc file, see The .netrc file.

To update your .netrc file, copy the following configuration to your .netrc file. The .netrc file locates in your $HOME directory. Create one if it doesn't exist.

copy
machine globaltech.alipay.com 
login YOUR_ACCOUNT 
password YOUR_PASSWORD
  1. Add dependencies in Podfile

Add the private source and dependency to your Podfile with the following code:

copy
source 'https://globaltech.alipay.com/api/v1/file/common/2017062215370883/minisdk'

target 'YOUR_TARGET' do

  pod 'IAPMiniProgram'

end

Note: The third-party library dependencies of the iOS IAPMiniProgram SDK might conflict with the version requirements of other SDKs or your app. It is recommended to thoroughly test your app's functionalities after integration. For more information, refer to Third-party library dependencies.

Step 4: Install the SDK

To install the SDK, run the pod install or pod install --repo-update command at the path of your Podfile.

If you encounter any problems when installing the SDK, refer to Troubleshooting CocoaPods CDN Source for troubleshooting.

Step 5: Initialize the SDK

To initialize the SDK, use the following code:

copy
import UIKit
import IAPConnect
import GRVAppContainer

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let config = IAPConnectInitConfig()
    IAPConnectClient.sharedInstance()?.initWithContext(config, success: {

    }, failure: { (error, errorMessage) in

                })
}

Nota that the code is recommended to be inserted in application(_:didFinishLaunchingWithOptions:)and needs to be run on the main thread.

Step 6: Implement SDK basic capabilities

Open a mini-program

To open a mini-program in your app, call either of the following APIs:

Obtain the mini-program list

To obtain the mini-program list in your app, call either of the following APIs:

  • fetchApps: Call this API to obtain the mini-program list with FetchAppRequestVO.
  • fetchAppInfosByIds: Call this API to obtain the mini-program list with mini-program IDs.

Next steps

The steps above focus on how to integrate the iOS IAPMiniProgram SDK and implement its basic capabilities. In addition to that, developers can selectively refer to the following chapters to implement advanced capabilities of the iOS IAPMiniProgram SDK.

  • Integrate Native SPIs: Refer this guide to implement the following services/capabilities: obtaining user authorization, accessing user information, processing payments, scanning QR codes and barcodes.
  • Integrate SDK components: To implement capabilities related to map, multi-media, or Bluetooth, refer to this guide to integrate the corresponding pre-defined SDK components.
  • Listen for SDK events: To perform specified operations on a certain event, refer to this guide to implement specific protocols to listen for SDK events.
  • Customize UI-related capacities: To customize certain user interfaces and related capacities, refer to this guide to implement specific protocols.
  • Customize JSAPIs: To extend SDK functionalities via JSAPIs, refer to this guide to create new JSAPIs and override the default implementation of built-in JSAPIs.
  • Open a mini program via a promotional QR code: To allow users to open mini programs and get benefits via promotional QR codes, refer to this guide to enable opening mini programs by scanning such codes.