Hi guys I tryed to implement ADBannerView with the old way like Objective C but unsuccessfull. Everythings work but the advertisments didn't show up, it stays a blank field.
func bannerViewDidLoadAd(banner: ADBannerView!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
banner.alpha = 1
UIView.commitAnimations()
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
banner.alpha = 0
UIView.commitAnimations()
}
Anyone who already tryed iAd on Swift ?
I've found a solution, how to implement it. (You can use inside each method "banner.alpha 1.0" or other things, too.)
See the following answer, on how to do it without IBBuilder!
Mr. T answer contains a lot of useless code.
All you need is this part to show ads in your controller:
And when you don't need ads, you
canDisplayBannerAds = false
.What it does — wrapping your controller into another controller with ad banner at the bottom. This feature is available since iOS7.
It's not possible to get delegate messages with it, so if you need it — you should replace it with
ADBannerView
instance variable.If you are using iOS 7, extension methods and properties have been added to UIViewController to support handling of iAd:
See
https://developer.apple.com/library/prerelease/ios/documentation/iAd/Reference/UIViewController_iAd_Additions/index.html
To show an iAd you first need to add the iAd framework, go to the projects properties, general tab, add the iAd.framework in the Linked framework and libraries section.
In your view controller, import iAd to access the iAd extensions. And finally in viewDidLoad, set self.canDisplayBannerAds = true.
To remove ads, set canDisplayBannerAds to false
Note there is no need to create an AdBannerView in the story board or programmatically and there is no need for your view controller to implement the AdViewDelegate.