-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3b0175
commit e8077ec
Showing
4 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Graduating-iOS/Graduating/Feature/Component/GoogleAdView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import SwiftUI | ||
import GoogleMobileAds | ||
|
||
public struct GoogleAdView: UIViewControllerRepresentable { | ||
public func makeUIViewController(context: Context) -> UIViewController { | ||
let viewController = UIViewController() | ||
let bannerSize = GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(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) | ||
#if DEBUG | ||
banner.adUnitID = "ca-app-pub-3940256099942544/2435281174" | ||
#else | ||
banner.adUnitID = "ca-app-pub-2589637472995872/3554240467" | ||
#endif | ||
banner.load(GADRequest()) | ||
return viewController | ||
} | ||
|
||
public func updateUIViewController(_ viewController: UIViewController, context: Context) {} | ||
} | ||
|
||
public extension GoogleAdView { | ||
struct BottomBannerPresenter<Banner: View, Label: View>: View { | ||
public let banner: () -> Banner | ||
public let label: () -> Label | ||
|
||
public init( | ||
@ViewBuilder banner: @escaping () -> Banner, | ||
@ViewBuilder label: @escaping () -> Label | ||
) { | ||
self.banner = banner | ||
self.label = label | ||
} | ||
|
||
public var body: some View { | ||
VStack(spacing: 0) { | ||
banner() | ||
label() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters