Reputation: 668
i have a view controller with a banner view, i integrate there an admob ads, i followed the official tutorial, but everytime i close ( not multitasking ) and open the app it's hide. Why ? I Added in the viewdidload this :
bannerView.adUnitID = "ca-app-pub-"
bannerView.rootViewController = self
let request = GADRequest()
request.testDevices = [ kGADSimulatorID ]
bannerView.loadRequest(request)
EDIT
When i run the app in my console there is :
Google Mobile Ads SDK version: afma-sdk-i-v7.5.2
2015-10-27 15:16:01.146 Chat for WhatsApp[25348:2400768] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x7fb9a4132e00 GADBannerView:0x7fb9a2f128e0.leading == UIView:0x7fb9a4131510.leadingMargin + 120>",
"<NSLayoutConstraint:0x7fb9a4137e10 H:|-(0)-[GADBannerView:0x7fb9a2f128e0] (Names: '|':UIView:0x7fb9a4131510 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fb9a4132e00 GADBannerView:0x7fb9a2f128e0.leading == UIView:0x7fb9a4131510.leadingMargin + 120>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-10-27 15:16:01.147 Chat for WhatsApp[25348:2400768] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x7fb9a4132db0 UIView:0x7fb9a4131510.trailingMargin == GADBannerView:0x7fb9a2f128e0.trailing + 120>",
"<NSLayoutConstraint:0x7fb9a4137e60 H:[GADBannerView:0x7fb9a2f128e0]-(0)-| (Names: '|':UIView:0x7fb9a4131510 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fb9a4132db0 UIView:0x7fb9a4131510.trailingMargin == GADBannerView:0x7fb9a2f128e0.trailing + 120>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-10-27 15:16:01.172 Chat for WhatsApp[25348:2400768] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<_UILayoutSupportConstraint:0x7fb9a4129e50 V:[_UILayoutGuide:0x7fb9a41321c0(0)]>",
"<_UILayoutSupportConstraint:0x7fb9a4129e00 _UILayoutGuide:0x7fb9a41321c0.bottom == UIView:0x7fb9a4131510.bottom>",
"<NSLayoutConstraint:0x7fb9a4132e50 V:[GADBannerView:0x7fb9a2f128e0]-(0)-[_UILayoutGuide:0x7fb9a41321c0]>",
"<NSLayoutConstraint:0x7fb9a41380d0 V:[GADBannerView:0x7fb9a2f128e0]-(1)-| (Names: '|':UIView:0x7fb9a4131510 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fb9a4132e50 V:[GADBannerView:0x7fb9a2f128e0]-(0)-[_UILayoutGuide:0x7fb9a41321c0]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-10-27 15:16:01.180 Chat for WhatsApp[25348:2400768] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x7fb9a2f07260 H:[GADBannerView:0x7fb9a2f128e0(320)]>",
"<NSLayoutConstraint:0x7fb9a4137e10 H:|-(0)-[GADBannerView:0x7fb9a2f128e0] (Names: '|':UIView:0x7fb9a4131510 )>",
"<NSLayoutConstraint:0x7fb9a4137e60 H:[GADBannerView:0x7fb9a2f128e0]-(0)-| (Names: '|':UIView:0x7fb9a4131510 )>",
"<NSLayoutConstraint:0x7fb9a2c1edf0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fb9a4131510(768)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fb9a2f07260 H:[GADBannerView:0x7fb9a2f128e0(320)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
it can be a constraints problem? i have a WKWebView and a View(banner view)
this are my constraints :
let viewsDictionary = ["top":webView, "bottom":bannerView]
let view_constraint_H:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[top]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
let view_constraint_H2:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[bottom]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
let view_constraint_V:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[top]-[bottom]-1-|", options: NSLayoutFormatOptions.AlignAllLeading, metrics: nil, views: viewsDictionary)
view.addConstraints(view_constraint_H as! [NSLayoutConstraint])
view.addConstraints(view_constraint_H2 as! [NSLayoutConstraint])
view.addConstraints(view_constraint_V as! [NSLayoutConstraint])
in advance my banner view is not 320x50 as i use it for iPad please help me, thank you very much in advance
Upvotes: 0
Views: 480
Reputation: 3690
Replace NSLayoutFormatOptions.AlignAllLeading
with NSLayoutFormatOptions(rawValue: 0)
, because it will try to add non-necessary constraints. Remove all constraints from Storyboard
First of all, declare new Constraint for Ad height in your ViewController, then create the constraint
let viewsDictionary = ["top":webView, "bottom":bannerView]
let view_constraint_H:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[top]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
let view_constraint_H2:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[bottom]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
let view_constraint_V:NSArray = NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[top]-[bottom]-1-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
view.addConstraints(view_constraint_H as! [NSLayoutConstraint])
view.addConstraints(view_constraint_H2 as! [NSLayoutConstraint])
view.addConstraints(view_constraint_V as! [NSLayoutConstraint])
constraintAdHeight = NSLayoutConstraint(item: bannerView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: getAdsHeight())
view.addConstraint(constraintAdHeight)
for this , you will need getAdsHeight()
method,
func getAdsHeight() -> CGFloat {
if(UIInterfaceOrientationIsPortrait(UIApplication.sharedApplication().statusBarOrientation)) {
return CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).height
} else {
return CGSizeFromGADAdSize(kGADAdSizeSmartBannerLandscape).height
}
}
and each time layout/orientation changes, you can update the height.
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews();
self.constraintAdHeight.constant = getAdsHeight()
}
You can also set the constraint.constant to 0 when Ads is hidden ( failed to load )
Upvotes: 1