iOS SwiftUI Example
In SwiftUI you can use FuseAdViewRepresentable wrapper around FuseAdView.
Simple use of FuseAdViewRepresentable
import SwiftUI
import FuseAppSDK
struct MyView: View {
var body: some View {
VStack {
FuseAdViewRepresentable(code: "<zone_code>")
.padding()
}
}
}
Advanced use of FuseAdViewRepresentable
FuseAdViewRepresentable has several extra parameters which can be provided to modify default behaviour:
loadingBehaviour- modifies behaviour ofFuseAdViewRepresentablewhen a new ad is loading (more information).errorBehaviour- modifies behaviour ofFuseAdViewRepresentablewhen there is a loading error (more information).params- extra parameters including custom targeting, content mapping or publisher provided identifiers.
import SwiftUI
import FuseAppSDK
struct MyView: View {
var body: some View {
VStack {
FuseAdViewRepresentable(
code: "<zone_code>",
loadingBehaviour: .progressBar,
errorBehaviour: .hide,
params: FuseAdViewParams(customTargeting: ["pos": "1"])
)
.padding()
}
}
}
Dynamic Updates
Sometimes you may need to set change the zone code dynamically (after the page first rendered). In this case, you should add an identifier to FuseAdViewRepresentable to ensure it gets re-rendered each time the zone code changes:
import SwiftUI
import FuseAppSDK
struct MyView: View {
@State var zoneCode = "<zone_code>"
var body: some View {
VStack {
...
FuseAdViewRepresentable(code: zoneCode)
.id(zoneCode)
}
}
}