我有一些使用谷歌Admob的自由职业者项目。现在,项目经理告诉我,这些项目不符合谷歌Admob的政策,显然谷歌暂时停止了为特定项目提供广告。
以下是Google Admob想要的理想流程(参考:
https://support.google.com/admob/answer/6201362?hl=en&ref_topic=2745287
):
据我所知,这种实现在iOS中是不可能的。目前项目所做的是在取消中间ad(通过Admob Framework的委派功能,
interstitialDidDismissScreen
或
interstitialWillDismissScreen
),然后才会显示下一个屏幕。简言之,在取消了模式呈现的中间广告后,下一个屏幕将被完美呈现!
我曾多次尝试这样做,当然,正如我们都知道的那样,结果是:
警告:试图显示其视图不在窗口层次结构中的对象!
所以我的问题是,有没有一种方法可以在显示的屏幕后面显示屏幕?
我尝试了其他一些方法,如删除动画,但仍然可以看到上一个屏幕。对于那些想尝试的人来说,这是一个简单的项目:
AppDelegate。敏捷的
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let vc1 = ViewController()
let vc1navcon = UINavigationController(rootViewController: vc1)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = vc1navcon
self.window?.makeKeyAndVisible()
return true
}
多个EVC。敏捷的
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .red
let barButton = UIBarButtonItem(title: "VC3", style: .plain, target: self, action: #selector(self.presentVc3))
self.navigationItem.leftBarButtonItem = barButton
}
@objc func presentVc3() {
let vc3navcon = UINavigationController(rootViewController: ViewController3())
self.present(vc3navcon, animated: true, completion: nil)
}
}
class ViewController2: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .green
}
}
class ViewController3: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .blue
let barButton = UIBarButtonItem(title: "AddVC2", style: .plain, target: self, action: #selector(self.addVc2))
self.navigationItem.leftBarButtonItem = barButton
let barButton2 = UIBarButtonItem(title: "dismiss", style: .plain, target: self, action: #selector(self.dismissVc3))
self.navigationItem.rightBarButtonItem = barButton2
}
@objc func dismissVc3() {
self.dismiss(animated: true, completion: {
})
}
@objc func addVc2() {
let vc2 = ViewController2()
let vc2navcon = UINavigationController(rootViewController: vc2)
var viewControllers = UIApplication.shared.keyWindow?.rootViewController?.childViewControllers
viewControllers?.append(vc2navcon)
}
}