Alipay+ Super App PlatformAlipay+ Super App Platform

renderWidget

Use the renderWidget API to handle the display of widgets and data collection.

Method signature

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

copy
func renderWidget(_ input: SpacePullInfo, containerView: UIView, actionDelegate: WidgetActionDelegate, completion: ((Result
                                                                         <SpaceContent?, ASAPBusinessWidgetError>) -> Void)? = nil)

Request parameters

Name

Type

Description

input

SpacePullInfo

SpacePullInfo object containing information about the requested space, including its code, pagination info, and any conditions or extended info.

containerView

UIView

A pre-allocated UIView placed in a designated area on the page to reserve space. Once the widget is created, the ASAPWidget component will render it onto the containerView as soon as possible.

actionDelegate

WidgetActionDelegate

SPIfor handling user click events

completion

(Result<SpaceContent, ASAPBusinessWidgetError>) -> Void

A closure that takes a Result containing either a SpaceContent object on success or a ASAPBusinessWidgetError on failure.

The Result type helps to concisely represent success or failure without the need for separate error handling.

Response parameters

N/A

Exception

Error code

Error message

1200

A network error has occurred.

1201

A backend error has occurred.

1202

The user ID is empty.

1203

A response payload is unavailable.

1400

A widget render error has occurred.

1500

  • SpaceContent is invalid.
  • SpaceCode is invalid.
  • ContentItems is invalid.
  • TemplateCode is invalid.
  • TemplateVersion is invalid.

Sample

Swift

copy
var spacePullInfo = SpacePullInfo(spaceCode: "SPACE_CODE_001")
spacePullInfo.pullOffsetInfo = PullOffsetInfo(overallOffset: 0, pullSize: 10)
spacePullInfo.conditions = ["longitude": "23.1234", "latitude": "100.4567"]
// Create a UIView in advance and place it in a specified location on the page to reserve a space. Once the widget is created, the ASAPWidget component will render it onto the containerView as soon as possible 
let containerView = UIView()
view.addSubview(containerView)
ComponentManager.ASAP.businessComponent.renderWidget(input:spacePullInfo containerView:containerView, actionDelegate: self, completion: { result in
    switch result {
         case .success(let success):
         print(success)
         case .failure(let failure):
         print(failure)
     }
})