Skip to content
:docs

Custom in-app browser

BuzzAd SDK for iOS passes the URL of the ad or content the user clicked to BZVLauncher. open determines which browser opens it: an external browser, Buzzvil's in-app browser or a custom in-app browser you implement.

The SDK's default launcher automatically chooses between an external browser and Buzzvil's in-app browser based on the ad settings. To use your own browser, implement the custom in-app browser, implement a custom launcher to open it, then configure it in BuzzAdBenefit.

Implement a custom in-app browser

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

Swift
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 in-app browser. You can define different behavior for ads and content. The content's sourceUrl may contain an app link.

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

Swift
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)
  }
}

Configure the custom launcher

Set your custom launcher in BuzzAdBenefit, as shown in the following example.

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