ハイブリッドアプリへの実装

    ハイブリッドアプリへの実装


    記事の要約

    ショートフォーム導入 - ハイブリッドアプリ

    [ステップ1] コードのインストール

    CocoaPods

    Podfile に以下のコードを追加してください。

    source 'https://github.com/CocoaPods/Specs.git'
    
        # Match the Version with the Project's Minimum Supported Version
        # Shoplive iOS SDK requires iOS 11.0 or later.
        platform :ios, '11.0'
        use_frameworks!
    
        # Set the Project Target for Shoplive iOS SDK Installation
        target 'ShortformProj' do
            pod 'ShopliveShortformSDK', '1.5.5'
          	pod 'ShopliveSDKCommon', '1.5.5'
        end

    Swift Package Manager

    Package Dependencies に以下のコードを追加してください。

    dependencies: [
        .package(url: "https://github.com/shoplive/shortform-ios", .exact(from: "1.5.5")),
        .package(url: "https://github.com/shoplive/common-ios", .exact(from: "1.5.5"))
    ]

    ❗️

    インストールに失敗した場合は、キャッシュをクリアしてください。

    ターミナルで次のコマンドを実行して、キャッシュをクリアします。

    rm -rf ~/Library/Caches/org.swift.swiftpm
    rm -rf ~/Library/org.swift.swiftpm

    [ステップ2] Web 連携

    ショートフォームのサービスを提供するには、最初にWeb統合を実行する必要があります。Web連携については、以下のリンクをご参照ください。

    [ステップ3]ネイティブコードを適用する

    UIViewController に下のコードを追加してください。Handler

    import ShopLiveShortformSDK
    
    class CustomerViewController: UIViewController {
        ...
        override func viewDidLoad() {
            super.viewDidLoad()
            ShopLiveShortform.BridgeInterface.connect(webview) // Required
            ShopLiveShortform.ShortsReceiveInterface.setHandler(self) // Required
        }
        ...
    }
    
    extension CustomerViewController: ShopLiveShortformReceiveHandlerDelegate {
        func handleShare(shareUrl: String) {
          // Do something
        }
        
        func onError(error: Error) {
          // Do something
        }
        
        func onEvent(command: String, payload: String?) {
          // Do something

    ShopLiveShortform.BridgeInterface

    Webview を BridgeInterface に接続すると、次のことが可能になります。

    • 商品画面を離れると、自動的にプレビュー再生を終了します。

    • ショートフォームのプレビュー再生、再生、および閉じるが機能します。

    // Connect Webview to BridgeInterface 
    ShopLiveShortform.BridgeInterface.connect(webview) // Required
    

    ShopLiveShortform.ShortsReceiveInterface

    Web UIViewController に ReceiveInterface ハンドラーを設定すると、次の callback を使用できます。

    // When the share button is pressed, it sends the share URL.
    func handleShare(shareUrl: String)
    
    // If an error occurs, it sends the error. 
    func onError(error: Error)
    
    // It forwards events that occur in Shortform.
    func onEvent(command: String, payload: String?)
    
    // It forwards the close event of Shortform screen.
    func onDidDisAppear()
    
    // It forwards the open event of Shortform screen.
    func onDidAppear()
    


    What's Next