Skip to main content

Add to wishlist

Wishlist integration connects the Bambuser player's wishlist UI to your app's native wishlist. There are five events to handle, covering the full wishlist lifecycle.

1. Provide Wishlist Status

When the player loads, it fires provide-wishlist-status to learn which products are already in the user's wishlist. Respond by calling invoke("updateWishlistStatus", ...) with a JSON map of sku → Bool.

func onNewEventReceived(id: String, event: BambuserEventPayload) {
switch event.type {

case "provide-wishlist-status":
guard let products = (event.data["event"] as? [String: Sendable])?["products"] as? [[String: Sendable]] else { return }

var statusMap: [String: Bool] = [:]
for product in products {
if let sku = product["ref"] as? String {
statusMap[sku] = YourWishlistService.isInWishlist(sku: sku)
}
}

Task {
let payload = ["statuses": statusMap]
if let jsonData = try? JSONSerialization.data(withJSONObject: payload),
let jsonString = String(data: jsonData, encoding: .utf8) {
try? await self.playerView?.invoke(
function: "updateWishlistStatus",
arguments: jsonString
)
}
}

default:
break
}
}

2. Add to Wishlist

Fires when a user taps the wishlist button on a product. Add the item to your wishlist and respond with notify.

case "add-to-wishlist":
guard let callbackKey = event.data["callbackKey"] as? String,
let sku = (event.data["event"] as? [String: Sendable])?["ref"] as? String else { return }

Task {
await YourWishlistService.add(sku: sku)
self.playerView?.notify(
callbackKey: callbackKey,
info: "{success: true, sku:'\(sku)'}"
)
}

3. Remove from Wishlist

Fires when a user taps the wishlist button again to remove a previously added product.

case "remove-from-wishlist":
guard let callbackKey = event.data["callbackKey"] as? String,
let sku = (event.data["event"] as? [String: Sendable])?["ref"] as? String else { return }

Task {
await YourWishlistService.remove(sku: sku)
self.playerView?.notify(
callbackKey: callbackKey,
info: "{success: true, sku:'\(sku)'}"
)
}

4. Open Wishlist

Fires when a user taps View Wishlist. Navigate to your app's native wishlist screen.

case "open-wishlist":
DispatchQueue.main.async {
self.navigateToWishlist()
}

5. Open Wishlist Login

Fires when an unauthenticated user attempts to wishlist a product. Present a login prompt, then respond with notify once the flow completes.

case "open-wishlist-login":
guard let callbackKey = event.data["callbackKey"] as? String else { return }

DispatchQueue.main.async {
self.showLoginPrompt {
self.playerView?.notify(callbackKey: callbackKey, info: "{ success: true }")
}
}

Event Summary

EventHas callbackKeyResponse
provide-wishlist-statusNoinvoke("updateWishlistStatus", jsonString)
add-to-wishlistYesnotify(callbackKey, "{success: true, sku:'...'}")
remove-from-wishlistYesnotify(callbackKey, "{success: true, sku:'...'}")
open-wishlistNoNavigate to wishlist screen
open-wishlist-loginYesShow login → notify(callbackKey, "{ success: true }")