please note: i am not professional code programing :)
Is there any error in the AdMob code, or any violation of AddMob ads, or any error in its combination?
//
// ViewController.swift
// المعلم الالكتروني الشامل
//
// Created by Majeed Raza on 12/11/20.
//
import UIKit
import WebKit
import GoogleMobileAds
class ViewController: UIViewController {
@IBOutlet weak var backButton: UIButton!
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var bannerContainerView: UIView!
@IBOutlet weak var bannerHeightConstraints: NSLayoutConstraint!
var bannerView: GADBannerView!
var interstitial: GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
createAndLoadInterstitial()
webView.navigationDelegate = self
= GADAdSizeFromCGSize(CGSize(width: 300, height: 50))
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
addBannerViewToView(bannerView)
bannerView.adUnitID = "ca-app-pub-8177765238464378/5568600849"
bannerView.rootViewController = self
bannerView.load(GADRequest())
bannerView.delegate = self
addBannerViewToView(bannerView)
// Do any additional setup after loading the view.
// webView.load(URLRequest.init(url: URL.init(string:
//let url = Bundle.main.url(forResource: "index", withExtension: "html")
// webView.load(URLRequest.init(url: url!))
do {
guard let filePath = Bundle.main.path(forResource: "index", ofType: "html")
else {
print ("File reading error")
return
}
let baseUrl = URL(fileURLWithPath: filePath)
webView.loadFileURL(baseUrl, allowingReadAccessTo: baseUrl)
} catch {
print ("File HTML error")
}
}
func addBannerViewToView( bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
bannerContainerView.addSubview(bannerView)
// bannerContainerView.frame = CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50)
}
@IBAction func backButtonTapped( sender: Any) {
webView.goBack()
}
func createAndLoadInterstitial() {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-8177765238464378/9061478519")
interstitial.delegate = self
interstitial.load(GADRequest())
}
}
extension ViewController: GADBannerViewDelegate {
func adViewDidReceiveAd( bannerView: GADBannerView) {
print("adViewDidReceiveAd")
bannerView.alpha = 0
bannerHeightConstraints.constant = 50
UIView.animate(withDuration: 0.1) {
self.view.layoutIfNeeded()
self.bannerView.alpha = 1
}
}
/// Tells the delegate an ad request failed.
func adView( bannerView: GADBannerView,
didFailToReceiveAdWithError error: GADRequestError) {
print("adView:didFailToReceiveAdWithError: \(error)")
bannerHeightConstraints.constant = 0
self.bannerView.alpha = 1
UIView.animate(withDuration: 0.1) {
self.view.layoutIfNeeded()
self.bannerView.alpha = 0
}
}
/// Tells the delegate that a full-screen view will be presented in response
/// to the user clicking on an ad.
func adViewWillPresentScreen( bannerView: GADBannerView) {
print("adViewWillPresentScreen")
}
/// Tells the delegate that the full-screen view will be dismissed.
func adViewWillDismissScreen( bannerView: GADBannerView) {
print("adViewWillDismissScreen")
}
/// Tells the delegate that the full-screen view has been dismissed.
func adViewDidDismissScreen( bannerView: GADBannerView) {
print("adViewDidDismissScreen")
}
/// Tells the delegate that a user click will open another app (such as
/// the App Store), backgrounding the current app.
func adViewWillLeaveApplication( bannerView: GADBannerView) {
print("adViewWillLeaveApplication")
}
}
extension ViewController: GADInterstitialDelegate {
func interstitialDidReceiveAd( ad: GADInterstitial) {
print("interstitialDidReceiveAd")
}
/// Tells the delegate an ad request failed.
func interstitial( ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) {
print("interstitial:didFailToReceiveAdWithError: \(error.localizedDescription)")
}
/// Tells the delegate that an interstitial will be presented.
func interstitialWillPresentScreen( ad: GADInterstitial) {
print("interstitialWillPresentScreen")
}
/// Tells the delegate the interstitial is to be animated off the screen.
func interstitialWillDismissScreen( ad: GADInterstitial) {
print("interstitialWillDismissScreen")
self.createAndLoadInterstitial()
}
/// Tells the delegate the interstitial had been animated off the screen.
func interstitialDidDismissScreen( ad: GADInterstitial) {
print("interstitialDidDismissScreen")
}
/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
func interstitialWillLeaveApplication( ad: GADInterstitial) {
print("interstitialWillLeaveApplication")
self.createAndLoadInterstitial()
}
}
extension ViewController: WKNavigationDelegate {
func webView( webView: WKWebView, didFinish navigation: WKNavigation!) {
if (webView.url?.absoluteString.contains("f1"))! || (webView.url?.absoluteString.contains("f2"))! {
if self.interstitial.isReady {
self.interstitial.present(fromRootViewController: self)
}
}
}
}
Post
Replies
Boosts
Views
Activity
moded@modeds-mbp ~ % sudo gem install cocoapods Password: Building native extensions. This could take a while... ERROR: Error installing cocoapods: ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/ext/ffic
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20201227-2974-utuq5f.rb extconf.rb checking for ffi.h... * extconf.rb failed * Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBYBASENAME) --with-ffic-dir --without-ffic-dir --with-ffic-include --without-ffic-include=${ffic-dir}/include --with-ffic-lib --without-ffic-lib=${ffic-dir}/lib --enable-system-libffi --disable-system-libffi --with-libffi-config --without-libffi-config --with-pkg-config --without-pkg-config /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in trydo': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in block in trycompile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in withwerror' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in trycompile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in block in haveheader' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in block in checkingfor' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block (2 levels) in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in checkingfor' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in haveheader' from extconf.rb:10:in systemlibffiusable?' from extconf.rb:42:in `'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2 for inspection. Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/gemmake.out