콘텐츠 상세 - 배너 광고 추가
This commit is contained in:
33
SodaLive/Sources/Advertisement/BannerAdView.swift
Normal file
33
SodaLive/Sources/Advertisement/BannerAdView.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// BannerAdView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/09/14.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
import GoogleMobileAds
|
||||
|
||||
struct BannerAdView: UIViewControllerRepresentable {
|
||||
|
||||
let adUnitId: String
|
||||
|
||||
func makeUIViewController(context: Context) -> some UIViewController {
|
||||
let viewController = UIViewController()
|
||||
|
||||
let bannerSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(UIScreen.main.bounds.width)
|
||||
let banner = GADBannerView(adSize: bannerSize)
|
||||
banner.rootViewController = viewController
|
||||
viewController.view.addSubview(banner)
|
||||
viewController.view.frame = CGRect(origin: .zero, size: bannerSize.size)
|
||||
|
||||
banner.adUnitID = adUnitId
|
||||
banner.load(GADRequest())
|
||||
|
||||
return viewController
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {}
|
||||
}
|
Reference in New Issue
Block a user