- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从 admobs 显示 GADInterstitial 后我遇到了问题。
我要做的是:
objc_msgSend() selector name: _setContentMargin:
import UIKit
import GoogleMobileAds
let kAD_UNIT_ID_BANNER_AD: String = "ca-app-pub-3940256099942544/2934735716"
let kAD_UNIT_ID_INTERSTITIAL_AD: String = "ca-app-pub-3940256099942544/4411468910"
let kVIEW_CONTROLLER_ALLOWS_TO_SHOW_INTERSTITIAL_NOTIFICATION: String = "kviewcontrollerallowstoshowinterstitialnotification"
class AdViewController: UIViewController, GADBannerViewDelegate {
var childController: UIViewController? {
didSet {
if self.childController != nil {
self.addChildViewController(self.childController!)
}
}
}
var contentView: UIView = UIView()
var adLayoutConstraint: NSLayoutConstraint?
let adView: UIView = UIView();
let gadAdView: GADBannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
var intAdView: GADInterstitial?
override func viewDidLoad() {
super.viewDidLoad()
if self.childController != nil {
self.view.addSubview(self.childController!.view)
self.contentView = self.childController!.view
self.contentView.translatesAutoresizingMaskIntoConstraints = false
}
self.view.addSubview(self.adView)
self.adView.translatesAutoresizingMaskIntoConstraints = false
self.adView.backgroundColor = UIColor.blackColor()
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[content]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["content":self.contentView]))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[ad]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["ad":self.adView]))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[content][ad]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["ad":self.adView, "content":self.contentView]))
self.adLayoutConstraint = NSLayoutConstraint(item: self.adView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 50
)
self.adView.addConstraint(self.adLayoutConstraint!)
self.adView.addSubview(self.gadAdView)
self.gadAdView.translatesAutoresizingMaskIntoConstraints = false
self.adView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[gad]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["gad":self.gadAdView]))
self.adView.addConstraint(NSLayoutConstraint(item: self.gadAdView, attribute: .CenterX, relatedBy: .Equal, toItem: self.adView, attribute: .CenterX, multiplier: 1, constant: 0))
//self.adView.addConstraint(NSLayoutConstraint(item: self.gadAdView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 320))
gadAdView.adUnitID = kAD_UNIT_ID_BANNER_AD
gadAdView.rootViewController = self
gadAdView.loadRequest(GADRequest())
gadAdView.delegate = self
self.hideBanner()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "askedForInterstitial:", name: kVIEW_CONTROLLER_ALLOWS_TO_SHOW_INTERSTITIAL_NOTIFICATION, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "initInterstitial", name: UIApplicationDidBecomeActiveNotification, object: nil)
// Do any additional setup after loading the view.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
func hideBanner() -> Void {
self.adLayoutConstraint?.constant = 0
self.view.layoutIfNeeded()
}
func showBanner() -> Void {
self.adLayoutConstraint?.constant = 50
self.view.layoutIfNeeded()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func initInterstitial() -> Void {
print("UIApplicationDidBecomeActiveNotification called!")
self.intAdView = GADInterstitial(adUnitID: kAD_UNIT_ID_INTERSTITIAL_AD)
let request = GADRequest()
self.intAdView?.loadRequest(request)
}
init(subController: UIViewController) {
super.init(nibName: nil, bundle: nil)
self.childController = subController
self.addChildViewController(self.childController!)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func adViewDidReceiveAd(bannerView: GADBannerView!) {
self.showBanner()
}
func adView(bannerView: GADBannerView!, didFailToReceiveAdWithError error: GADRequestError!) {
self.hideBanner()
}
func askedForInterstitial(notification:NSNotification) -> Void {
if notification.userInfo != nil {
if let c = notification.userInfo!["controller"] as? UIViewController {
self.showInterstitialInController(c)
} else {
self.showInterstitialInController(self)
}
} else {
self.showInterstitialInController(self)
}
}
class func presentInterstitial() -> Void {
AdViewController.presentInterstitialInController(nil)
}
class func presentInterstitialInController(c: UIViewController?) {
if c == nil {
NSNotificationCenter.defaultCenter().postNotificationName(kVIEW_CONTROLLER_ALLOWS_TO_SHOW_INTERSTITIAL_NOTIFICATION, object: nil)
}
else {
NSNotificationCenter.defaultCenter().postNotificationName(kVIEW_CONTROLLER_ALLOWS_TO_SHOW_INTERSTITIAL_NOTIFICATION, object: nil, userInfo: ["controller": c!])
}
}
private func showInterstitialInController(c: UIViewController) -> Void {
if self.intAdView != nil && self.intAdView!.isReady {
self.intAdView!.presentFromRootViewController(c)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
presentInterstitial
和
presentInterstitialInController
层次结构中的所有 childviewcontrollers 都可以要求显示插页式广告。这很好用,但正如我所说,问题接缝发生在应用程序在后台之后。
最佳答案
好的,我已经解决了...
问题不在于插页式广告,而是我为 UIApplicationDidBecomeActiveNotification
添加观察者的那一行。通知名称:
我有一个功能:
func initInterstitial() -> Void {
print("UIApplicationDidBecomeActiveNotification called!")
self.intAdView = GADInterstitial(adUnitID: kAD_UNIT_ID_INTERSTITIAL_AD)
let request = GADRequest()
self.intAdView?.loadRequest(request)
}
NSNotificationCenter.defaultCenter().addObserver(self, selector: "initInterstitial", name: UIApplicationDidBecomeActiveNotification, object: nil)
createInterstital
:
func createInterstitial() -> Void {
print("UIApplicationDidBecomeActiveNotification called!")
self.intAdView = GADInterstitial(adUnitID: kAD_UNIT_ID_INTERSTITIAL_AD)
let request = GADRequest()
self.intAdView?.loadRequest(request)
}
NSNotificationCenter.defaultCenter().addObserver(self, selector: "createInterstitial", name: UIApplicationDidBecomeActiveNotification, object: nil)
关于ios - GADInterstitial presentFromRootViewController : causes crash after app resigns from background,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35430156/
我想检查有效的负载类型。如果传递到我的过程中的加载类型无效,我想通过 SIGNAL 抛出错误消息。我还希望有一个通用的 EXIT 处理程序来处理任何其他意外错误,这将回滚任何更改。问题是通用 EXIT
我正在尝试使用 watch 应用程序退出 ios 应用程序。像往常一样,我删除了 _CodeSignature 文件夹,运行 codesign 以及配置、证书和权利。它完成时没有错误,这是预期的。 B
我正在使用以下终端命令对 ipa 重新签名:我解压缩 ipa,复制到新的移动配置文件中,使用签名标识运行代码签名,然后将其压缩回 ipa。 unzip -q My_App_Name.app cp Ne
我创建了警报 View ,在警报 View 中会出现一个文本字段,但是当我单击键盘上的返回按钮时它不会消失,即使我将委托(delegate)添加到 .h 文件。 -(BOOL)textFieldSho
从 admobs 显示 GADInterstitial 后我遇到了问题。 我要做的是: 使用 presentFromRootViewController 打开 GADInterstitial: 关闭它
我正在尝试为我的登录页面编写 UI 测试。该页面有一些介绍动画、一个搜索字段(用于查找要连接的正确服务器),然后一旦他们选择了正确的服务器,就会出现一个用户名和密码字段。 到目前为止,这是我的测试:
我必须退出最初使用企业配置文件签名的 .ipa 文件。由于安全原因,我无法访问该项目的存储库。另外,我必须修改内部版本号.plist 文件。 首先,我使用 faSTLane 使用我的分发证书和应用商店
我正在尝试为复合控件构建一个通用祖先。最初的想法是这样的: type TCompositeControl = class(TWinControl) private FControl1,
我是一名优秀的程序员,十分优秀!