renderWidget
Use the renderWidget API to create and render view compontents based on templates.
Method signature
The following code shows the method signature of the renderWidget API:
func renderWidget(containerView: UIView, dataModel: WidgetDataModel, actionDelegate: WidgetActionDelegate, completion: ((Result<Void, WidgetError>) -> Void)? = nil) Request parameters
Name | Type | Description |
containerView | UIView | A pre-allocated |
dataModel | Data model of the | |
actionDelegate | WidgetActionDelegate |
|
completion | (Result<Void, WidgetError>) -> Void | A closure that takes a The |
Response parameters
N/A
Exception
Error Code | Error message |
1400 | A widget render error has occurred. |
Sample
Swift
// 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)
var dataModel = WidgetDataModel(templateCode: "ac-sign", templateVersion: "1.0.0")
dataModel.content = ["templateCode":"ac-sign_in","templateVersion":"1.0.0","content":["viewType":"viewTypeDummy"]]
dataModel.extendedInfo = ["extras1":"extras1Dummy"]
dataModel.spmInfo = ["spm1":"spm1Dummy"]
ComponentManager.ASAP.widgetComponent.renderWidget(containerView: containerView, dataModel: dataModel, actionDelegate: self, completion: { result in
switch result {
case .success:
print("success")
case .failure(let error):
print(error.debugDescription)
}
})