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.
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)
}
}
@interface CustomBrowserViewController: UIViewController
@end
@interface CustomBrowserViewController ()
@property (nonatomic, strong, readonly) UIViewController *browserViewController;
@end
@implementation CustomBrowserViewController
- (void)viewDidLoad {
[super viewDidLoad];
_browserViewController = [BuzzAdBrowser.sharedInstance browserViewController];
[self displayContentViewController:_browserViewController];
}
- (void)displayContentViewController:(UIViewController *)contentViewController {
[self addChildViewController:contentViewController];
contentViewController.view.frame = self.view.bounds;
[self.view addSubview:contentViewController.view];
[contentViewController didMoveToParentViewController:self];
}
@end
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.
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)
}
}
@import BuzzAdBenefit;
@interface CustomLauncher : NSObject <BZVLauncher>
// 런처와 관련된 이벤트를 수신할 수 있습니다.
@property (nonatomic, weak, readwrite, nullable) id<BZVLauncherDelegate> delegate;
@end
@implementation CustomLauncher
- (void)openWithLaunchInfo:(BZVLaunchInfo *)launchInfo {
// launchInfo의 인자를 확인하여 광고 또는 콘텐츠인지 미리 판단할 수 있습니다.
if (launchInfo.ad != nil) {
if (ad.isDeepLink) {
// 딥링크 광고일 경우 필요한 작업을 할 수 있습니다.
}
} else if (launchInfo.article != nil){
NSString *sourceURL = launchInfo.article.sourceURL;
}
// Custom Browser 실행
CustomBrowserViewController *customBrowserViewController = [[CustomBrowserViewController alloc] init];
[YOUR_ROOT_VIEW_CONTROLLER.presentedViewController presentViewController:customBrowserViewController animated:YES completion:nil];
}
@end
Configure the custom launcher
Set your custom launcher in BuzzAdBenefit, as shown in the following example.
let launcher = CustomLauncher()
BuzzAdBenefit.setLauncher(launcher)
CustomLauncher *launcher = [[CustomLauncher alloc] init];
[BuzzAdBenefit setLauncher:launcher];