Skip to content
:docs

Custom in-app browser

Buzzvil SDK passes the URL of the clicked ad or content to BZVLauncher. open determines which browser opens it: an external browser, Buzzvil's in-app browser or your own custom browser.

The default launcher chooses between an external browser and Buzzvil's in-app browser according to ad settings. To use your own browser, implement it, create a custom launcher and register it in BuzzAdBenefit.

Implement a custom in-app browser

The following example implements a custom browser. You must use [BuzzAdBrowser.sharedInstance browserViewController]; otherwise, action-based ads and time-based reward ads may not work correctly.

Swift
import UIKit
import BuzzvilSDK

final class CustomBrowserViewController: UIViewController {
  private lazy var browserViewController: UIViewController = {
    BuzzAdBrowser.sharedInstance().browserViewController()
  }()
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    displayContentViewController(browserViewController)
  }

  private func displayContentViewController(_ contentViewController: UIViewController) {
    addChild(contentViewController)
    contentViewController.view.frame = view.bounds
    view.addSubview(contentViewController.view)
    contentViewController.didMove(toParent: self)
  }
}

Implement a custom launcher

Implement a custom launcher to use your browser. You can define different behavior for ads and content, and the content's sourceUrl may contain app links.

The following example implements a custom launcher that opens ads in your browser.

Swift
import Foundation
import BuzzvilSDK

final class CustomLauncher: NSObject, BZVLauncher {
  // 런처와 관련된 이벤트를 수신할 수 있습니다.
  var delegate: BZVLauncherDelegate?

  func open(with launchInfo: BZVLaunchInfo) {
    // launchInfo의 인자를 확인하여 광고 또는 콘텐츠인지 미리 판단할 수 있습니다.
    if let ad = launchInfo.ad {
      if ad.isDeepLink {
        // 딥링크 광고일 경우 필요한 작업을 할 수 있습니다.
      }
    } else if let article = launchInfo.article {
      let sourceURL = article.sourceURL
    }

    let customBrowserViewController = CustomBrowserViewController()
    YOUR_ROOT_VIEW_CONTROLLER.presentedViewController?.present(customBrowserViewController, animated: true, completion: nil)
  }
}

Register the custom launcher

Register your custom launcher in BuzzAdBenefit as shown below.

Swift
let launcher = CustomLauncher()
BuzzAdBenefit.setLauncher(launcher)