Quickstart
This topic introduces how to quickly set up iOS IAPMiniProgram SDK and implement basic mini-program capabilities.
Before you begin
Before you get started, ensure that the following requirements are met:
- To run mini-programs, your device needs to be iOS 11 or higher.
- Xcode 14.0 or higher is installed on your computer.
- CocoaPods 1.10.0 or higher is installed on your computer.
Get started
To get started with IAPMiniProgram SDK, perform the following actions:
Step 1: Download the SDK
Log in to Mini Program Platform, go to the App Manage page, and click Resource > iOS Resource to download IAPMiniProgram SDK for iOS. 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 as shown in the following screenshot.
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.
Step 3: Update your .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, take the following steps:
- Copy the configuration below to your .netrc file. The .netrc file locates in your
$HOME
directory. Create one if it doesn't exist.
machine globaltech.alipay.com
login YOUR_ACCOUNT
password YOUR_PASSWORD
- Add the private source and dependency to your Podfile with the following code:
source 'https://globaltech.alipay.com/api/v1/file/common/2017062215370883/minisdk'
target 'YOUR_TARGET' do
pod 'IAPMiniProgram'
end
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:
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:
- openAppWithApppId: Call this method to open a mini-program with appId.
- openAppWithUrl: Call this method to open a mini-program with a URL.
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 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 iOS IAPMiniProgram SDK.
- 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.