Handler
ショートフォームで生成された通知は、クライアントから ShopLiveShortformReceiveHandlerDelegate
関数を通じて渡され、必要に応じて処理します。
protocol ShopLiveShortformReceiveHandlerDelegate : AnyObject {
@objc optional func handleShare(shareMetadata : ShopLiveShareMetaData)
@objc optional func onError(error: Error)
@objc optional func onEvent(command: String, payload: String?)
@objc optional func onDidAppear()
@objc optional func onDidDisAppear()
}
// Adopting Handler
class ViewController : ShopLiveShortformReceiveHandlerDelegate {
override func viewDidLoad(){
super.viewDidLoad()
ShopLiveShortform.ShortsReceiveInterface.setHandler(self)
}
}
onEvent(command: String, payload: String?)
ショートフォームで発生する複数のイベントを直接処理できる messageCallback 関数を提供します。
ショートフォームイベントリスト
onError(error: Error)
ショートフォームで発生するエラーを直接処理できる messageCallback 関数を提供します。
Type | 説明: |
---|
statusCode | ネットワーク応答状態コード エラー |
invalidConfig | ショートフォーム構成エラー |
other | その他のエラー |
public enum ShortformError: Error {
case statusCode(Int)
case invalidConfig
case other(Error)
var errorMessage: String {
switch self {
case .statusCode(let code):
return "[Http status code : statusCode(\(code))] To use Shoplive Short-form, please contact ask@shoplive.cloud."
case .invalidConfig:
return "[Invalid config] To use Shoplive Short-form, please contact ask@shoplive.cloud."
case .other(let error):
return "[Other error] \(error.getErrorMsg())"
}
}
}
handleShare(shareMetaData: ShopLiveShareMetaData)
ショートフォームを直接共有するための機能を開発します。
フィールド | タイプ | 説明 |
---|
shortsId | String? | ショートフォームのユニークID |
shortsSrn | String? | ショートフォームの固有情報を含む ID |
title | String? | ショートフォームのタイトル(og タグ用) |
descriptions | String? | ショートフォームの説明 (og タグ用) |
thumbnail | String? | ショートフォームのサムネイル(og タグ用) |
class ViewController : ShopLiveShortformReceiveHandlerDelegate {
func handleShare(shareMetaData: ShopLiveShareMetaDatag) {
//Do something
}
}
onDidAppear()
ショートフォームの詳細画面が全画面で展開されたイベントを受け取ることができます。
class ViewController : ShopLiveShortformReceiveHandlerDelegate {
func onDidAppear() {
//ex) stop ListView player when entering Shortform detail
builder?.disablePlayVideos()
}
}
onDidDisAppear()
ショートフォームの詳細画面が終了したイベントを受け取ることができます。
class ViewController : ShopLiveShortformReceiveHandlerDelegate {
func onDidDisAppear(shareUrl: String) {
//ex) play ListView players when ListView reappeared
builder?.enablePlayVideos()
}
}
Shoplive Short-formで発生した通知をクライアントがShopLiveShortformDetailHandlerDelegate関数を通じて受け取り、必要に応じて処理します。
class ViewController : ShopLiveShortformDetailHandlerDelegate {
func handleProductItem(shortsId : String, shortsSrn : String, product : Product){ }
func handleProductBanner(shortsid : String, shortsSrn : String, scheme : String, shortsDetail : ShortsDetail){ } )
}
ShopLiveShortform.ShortsReceiveInterface.setDetailHandler(self)
handleProductItem(shortsId : String、shortsSrn : String、product : Product)
ショートフォーム内での商品クリックに関する機能を開発することができます。
class ViewController : ShopLiveShortformNativeHandlerDelegate {
func handleProductItem(shortsId : String, shortsSrn : String, product : Product) {
//ex) Show preview when product is clicked with sku
ShopLiveShortform.showPreview(requestData: ShopLiveShortformRelatedData(sku: product.sku))
}
}
フィールド | タイプ | 説明 |
---|
brand | String? | 商品のブランド情報 |
currency | String? | 商品の通貨 |
description | String? | 商品の説明 |
discountPrice | Double? | 商品の割引価格 |
discountRate | Double? | 商品の割引率 |
imageUrl | String? | 商品画像URL |
name | String? | 商品名 |
originalPrice | Double? | 商品の通常価格 |
productId | String? | 商品のユニークID。 登録時にShopliveが自動発行 |
showPrice | Boolean | 商品の表示価格 |
sku | String? | 商品固有のSKU情報(商品登録時に入力したもの) |
url | String? | 商品詳細ページのURL |
handleProductBanner(shortsid : String, shortsSrn : String, scheme : String, shortsDetail : ShortsDetail)
ショートフォーム内でのバナークリックに関する機能を開発することができます。
class ViewController : ShopLiveShortformNativeHandlerDelegate {
func handleProductBanner(shortsid : String, shortsSrn : String, scheme : String, shortsDetail : ShortsDetail) { {
}
}