- Print
API: Etc
- Print
mute
Mute the currently playing video.
Sample code
unmute
Unmute the currently playing video.
Sample code
getCampaigns
Retrieves the list of campaigns (broadcasts) that belong to the accessKey, together with the current status of each campaign. Set the accessKey with ShopLive.configure(with:) before calling. Available in iOS SDK 1.8.15 and later.
extension ShopLive.API {
// completion
@discardableResult
static func getCampaigns(_ request: ShopLiveCampaignListRequest = ShopLiveCampaignListRequest(),
completion: @escaping (Result<ShopLiveCampaignListResponse, ShopLiveCommonError>) -> Void) -> ShopLiveCancellable
// async/await (iOS 13+)
static func getCampaigns(_ request: ShopLiveCampaignListRequest = ShopLiveCampaignListRequest()) async throws -> ShopLiveCampaignListResponse
}Note
The completion handler is called on the main thread.
Call
cancel()on the returnedShopLiveCancellableto cancel a request in progress. With the async version, cancelling theTaskalso cancels the request.The request and response types are defined in the
ShopliveSDKCommonmodule. Addimport ShopliveSDKCommonwhen you refer to the type names directly in code.
ShopLiveCampaignListRequest
Query conditions. Every parameter is optional; passing ShopLiveCampaignListRequest() with no arguments fetches all statuses with the server defaults.
Parameter name | Type | Description |
|---|---|---|
page |
| Page number, starting at 1. (Default: 1) |
size |
| Number of campaigns per page. Maximum 20. (Default: 10) |
statuses |
| Status filter. An empty array fetches every status. Only |
order |
| Sort direction by scheduledAt. |
ShopLiveCampaignListResponse
The query result.
Property | Type | Description |
|---|---|---|
campaigns |
| The campaigns that were fetched. |
hasMore |
| Whether a next page exists. If true, increase page by 1 and query again. |
ShopLiveCampaign
Information about a single campaign.
Property | Type | Description |
|---|---|---|
campaignId |
| Campaign ID |
campaignKey |
| Campaign key. Use it as the campaignKey for |
title |
| Campaign title |
description |
| Campaign description |
campaignUrl |
| Campaign URL |
rerun |
| Whether the campaign is a rerun. |
archiveStream |
| Whether an archived stream (replay) is provided. |
privateLive |
| Whether the campaign is a private broadcast. It is still included in the list, so the app decides whether to show it. |
scheduledAt |
| Scheduled start time |
scheduledEndAt |
| Scheduled end time |
posterUrl |
| Poster image URL |
lifecycle |
| Status and status-transition timestamps |
metrics |
| Viewing metrics. Returned only in the |
ShopLiveCampaign.Lifecycle
The status of the campaign and the timestamps of its status transitions.
Property | Type | Description |
|---|---|---|
status |
| Campaign status. A rehearsal is reported as |
rehearsal |
| Whether the campaign is in rehearsal. The status stays |
startedAt |
| Time the broadcast started |
closingAt |
| Time the closing process started. When the status is |
endedAt |
| Time the broadcast ended |
ShopLiveCampaign.Status
Campaign status values. Server values are mapped as-is; an undefined value is delivered as .unknown.
Case | Server value | Description |
|---|---|---|
| RESERVED | Reserved broadcast. It cannot be specified in the request filter (statuses) and is included only when fetching all statuses. |
| READY | Preparing (standby). If lifecycle.rehearsal is true, the campaign is in rehearsal. |
| ONAIR | On air. If lifecycle.closingAt is present, the broadcast is closing. |
| CLOSED | Broadcast ended |
| Other | An undefined server status value. The raw string is preserved to accommodate statuses added in the future. |
ShopLiveCampaign.Metrics
Viewing metrics. Provided only in the .onair / .closed statuses.
Property | Type | Description |
|---|---|---|
userCount |
| Number of viewers |
adoreCount |
| Number of likes (hearts) |
showUserCount |
| If false, userCount / adoreCount must not be shown in the UI. |
Error handling
On failure a ShopLiveCommonError is delivered. codes holds the error code, and message is always the fixed text Failed to fetch campaign list. Refer to the error code. Determine the cause from codes. Error codes returned by the server are passed through as-is; see the Error codes document for the full list.
Code | Description |
|---|---|
9000 | The accessKey is not set. Call |
-200 | The accessKey does not exist. (Customer Account Not Found) |
Other server error codes | Error codes returned by the server are passed through as-is. See the Error codes document. |
HTTP status code | If the server responds without an error body, the HTTP status code (e.g. 404, 500) is passed through as-is. |
9900 | Network connection failed. |
9901 | Failed to parse the response JSON. |
10000 | Unexpected error. |
Sample code
import ShopLiveSDK
import ShopliveSDKCommon
// Set the accessKey (once per app launch)
ShopLive.configure(with: "{accessKey}")
// Fetch up to 20 on-air and preparing campaigns, newest first
let request = ShopLiveCampaignListRequest(page: 1,
size: 20,
statuses: [.onair, .ready],
order: .descending)
let cancellable = ShopLive.API.getCampaigns(request) { result in
switch result {
case let .success(response):
for campaign in response.campaigns {
switch campaign.lifecycle.status {
case .reserved:
print("Reserved", campaign.title ?? "")
case .ready:
print(campaign.lifecycle.rehearsal ? "Rehearsal" : "Preparing", campaign.title ?? "")
case .onair:
print(campaign.lifecycle.closingAt == nil ? "On air" : "Closing", campaign.title ?? "")
case .closed:
print("Closed", campaign.title ?? "")
case let .unknown(raw):
print("Unknown status", raw)
}
}
if response.hasMore {
// Increase page by 1 and fetch the next page.
}
case let .failure(error):
print("getCampaigns failed:", error.codes, error.message ?? "")
}
}
// Cancel the request when the result is no longer needed (e.g. the screen is dismissed).
// cancellable.cancel()Sample code (async/await)
// iOS 13+ — cancelling the Task also cancels the request in progress.
Task {
do {
let response = try await ShopLive.API.getCampaigns(ShopLiveCampaignListRequest(statuses: [.onair]))
let onair = response.campaigns.filter { $0.lifecycle.closingAt == nil }
if let campaign = onair.first {
ShopLive.play(data: ShopLivePlayerData(campaignKey: campaign.campaignKey))
}
} catch let error as ShopLiveCommonError {
print("getCampaigns failed:", error.codes)
} catch {
// Task cancellation (CancellationError), etc.
}
}