Alipay+ Super App PlatformAlipay+ Super App Platform

init

Initialize the application using the configure API.

Method signature

The following code shows the method signature of the configure API:

copy
public static func configure(configuration: Configuration? = nil) throws

Request parameters

Name

Type

Description

configuration

Configuration?

Provides optional and additional configuration for the SDK.

Response parameters

N/A

Exception

Error Code

Error message

1001

Initialization failed because the configuration file could not be read. Please check if the assets/ASAPLocalConfiguration.json file is correctly configured.

1002

A system error has occurred

1003

Initialization failed because the ASAP configuration was not found.

Sample

Swift

copy
import UIKit
import ASAPCore

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    var configuration = Configuration()
    // Configure SPI for obtaining user ID
    configuration.fetchUserId = { _ in "ASAPTestUserId" }
    // Configure signature mode for network request
    configuration.rpcSingerMode = .helper(key: "rpcSingerModeHelperKey", authCode: "rpcSingerModeHelperAuthCode")
    // Configure settings for ASAPBusiness
    var asapConfiguration = Configuration.ASAPConfiguration()
    asapConfiguration.presetWidgetTemplateFilePath = Bundle.main.path(forResource: "ASAPBusinessWidgetTemplates", ofType: "json")
    configuration.ASAP = asapConfiguration

    do {
        try ComponentManager.configure(configuration: configuration)
    } catch let error as ASAPError {
        switch error {
            case .localConfigurationFileNotFound:
            print("Error Code: \(error.code), Description: \(error.debugDescription)")
            case .noSpecificBusinessTypesAvailable(business: let business):
            print("Error Code: \(error.code), Description: \(error.debugDescription), Business: \(business)")
            case .systemError(_):
            print("Error Code: \(error.code), Description: \(error.debugDescription)")
        }
    } catch {
        print("Unknown error: \(error)")
    }
}