1. Add Alipay+ SDK to your project
Before you start
Make sure you meet the following system requirements:
- iOS 11 or above
- Xcode 14.0 or higher
- Cocoapods 1.10.0 or higher
Get started
To get started with IAPMiniProgram SDK, perform the following actions:
Step 1: Add the configuration file
After completed the settings in the Preparation stage,you will receive a file named iapconnect_config_full. 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 2: 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
In the code above, the values of YOUR_ACCOUNT and YOUR_PASSWORD are desensitized. To obtain the sample codes with the values, see Credentials.
- 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 3: 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 4: 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.