Last active
October 21, 2022 11:06
-
-
Save donchan922/614ed862f7c7146fc0c94631189978d8 to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
import GoogleMobileAds | |
struct AdView: UIViewRepresentable { | |
func makeUIView(context: Context) -> GADBannerView { | |
let banner = GADBannerView(adSize: kGADAdSizeBanner) | |
// 以下は、バナー広告向けのテスト専用広告ユニットIDです。自身の広告ユニットIDと置き換えてください。 | |
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716" | |
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController | |
banner.load(GADRequest()) | |
return banner | |
} | |
func updateUIView(_ uiView: GADBannerView, context: Context) { | |
} | |
} | |
struct ContentView: View { | |
var body: some View { | |
AdView() | |
// サイズを変更する場合 | |
// AdView().frame(width: 320, height: 50) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
how to embed adView in another UIViewRepresentable. I want to integrate a banner in a wkwebview
Thank You