swift
1import UIKit 2import GoogleMobileAds 3class QuizViewController: UIViewController { 4 5 @IBOutlet weak var judgeImageView: UIImageView! 6 var BannerView: GADBannerView! 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 11 BannerView = GADBannerView(adSize: kGADAdSizeBanner) 12 addBannerViewToView(BannerView) 13 BannerView.adUnitID = "ca-app-pub-7967816978520304/2883950888" 14 BannerView.rootViewController = self 15 BannerView.load(GADRequest()) 16 } 17 18 func addBannerViewToView(_ bannerView: GADBannerView) { 19 bannerView.translatesAutoresizingMaskIntoConstraints = false 20 view.addSubview(bannerView) 21 view.addConstraints( 22 [NSLayoutConstraint(item: bannerView, 23 attribute: .bottom, 24 relatedBy: .equal, 25 toItem: view.safeAreaLayoutGuide, 26 attribute: .bottom, 27 multiplier: 1, 28 constant: 0), 29 NSLayoutConstraint(item: bannerView, 30 attribute: .centerX, 31 relatedBy: .equal, 32 toItem: view, 33 attribute: .centerX, 34 multiplier: 1, 35 constant: 0) 36 ]) 37 } 38 39 40}
info.listには
GADApplicaionIdentifier:アプリID
GADIsAdManagerApp:true
がセットされています。
広告の初期化
swift
1import UIKit 2import GoogleMobileAds 3@main 4class AppDelegate: UIResponder, UIApplicationDelegate { 5 6 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 7 // Override point for customization after application launch. 8 GADMobileAds.sharedInstance().start(completionHandler: nil) 9 return true 10 } 11 12 // MARK: UISceneSession Lifecycle 13 14 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 15 // Called when a new scene session is being created. 16 // Use this method to select a configuration to create the new scene with. 17 return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 18 } 19 20 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { 21 // Called when the user discards a scene session. 22 // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 23 // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 24 } 25 26 27}
Podfile
1target 'SampleQuiz' do 2 use_frameworks! 3 4 pod 'Google-Mobile-Ads-SDK' 5 6end
ライブラリ更新済み
ここまでではネット上の記事を色々見回しましたがこれといって間違っていることは見当たりません。。
考えられるとしたら何があげられるでしょうか。
AppDelegateでなぜ「GoogleMobileAds」をimportするのでしょうか?AppDelegateの中でApplicationIDが設定されていないように見えるんですけど?
回答1件
あなたの回答
tips
プレビュー