iAd Banner swift , after i added iAd the game started crash - ios

i developed this game , and it works fine like i want it to do , but after i added the iAd banner , when i start the game it would run normally for like 10 sec. and the it zoom in and make every thing very large and then it would give me this error :
Shapes#2[75422:7643415] [AppDeveloper] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=1 "Service session terminated." UserInfo=0x7fdb09f5b1e0 {ADInternalErrorCode=1002, NSLocalizedDescription=Service session terminated.}

You're missing your didFailToReceiveAdWithError function. You can copy and paste this code in, just make sure you iAd banner matches what is in your project:
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
println("Error failed to load. Probably due to network connection.")
self.adBannerView.hidden = true//hide the banner
}
The problem is probably the iAd banner cannot load and you don't have the didFailToReceiveAdWithError function which runs when the banner can't load. If the banner doesn't load, and there's no function to handle this, the compiler will complain.
P.S. You may want to insert this function too. This one is the opposite of didFailToReceiveAdWithError, it runs when the banner can load.
func bannerViewDidLoadAd(banner: ADBannerView!) {
println("Banner did load.")
self.adBannerView.hidden = false//show banner
}
You can find more info about iAd here.

Related

AdMob area is not clickable after being hidden

I've a tableview which displays advertisement if user is NOT premium. But in this case if the user IS premium I'm hiding the advertisement by adding this code:
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError)
{
advertisementBanner.isHidden = true
topConstraint.constant = 0
tableView.layoutIfNeeded()
tableView.updateConstraints()
}
So, when I run this code and the advertisement is hidden I can't still tap on the area where the advertisement is located. Its like its still there but hidden, and I've no idea how I can solve this issue.
So my question is: How can I make the area where my ad is located clickable if the ad is NOT shown? I hope you understand what I mean.
Try this
advertisementBanner.isUserInteractionEnabled = false

Removing RevMob Ad banner upon in-App purchase

The problem is that Apple rejects my app because when the button is clicked to purchase the "no ads" upgrade, it doesn't make the banner disappear until you close the app and re-open it. This is because I initialize all my RevMob code in the viewController.swift file. I have a boolean in place that turns to false as soon as the upgrade is purchase inside this viewController.swift file. So next time you open the app and the viewController loads, the boolean is set to false and it doesn't allow the ads to appear.
Anybody know if this is the wrong way to go about this? Or is there an easy way to make them disappear immediately upon press of the no Ads button without having to close the app and re-open it?
//BANNER AD =======================================
let bannerBlock: () -> Void = {
//Custom method defined below
if UserDefaults.standard.object(forKey: "adsBool") as! Bool == true
{
self.showBannerWithCustomFrame()
}
else
{
//don't show ads because user purchased
}
}
let bannerFailBlock: ((Error?) -> Void) = {error in
NSLog("[RevMob Sample App] Session failed to start with error: \(error!.localizedDescription)")
}
RevMobAds.startSession(withAppID: "00000000000000000000",
withSuccessHandler: bannerBlock,
andFailHandler: bannerFailBlock)
This is how my bannerView is set up in my GameViewController
class GameViewController: UIViewController, RevMobAdsDelegate {
var bannerView:RevMobBannerView?
override func viewDidLoad() {
super.viewDidLoad()
From RevMob's banner documentation, there's a method called hideAd. Calling that method on the IAP callback would solve your problem right?
To hide the banner:
banner!.hideAd()
Let me see if i got your problem correctly, you want to hide your banner as soon as the purchase is made.
First, you need to set the bannerView as a property of your viewController.
Then you have to add this code inside the callback from the purchase success:
viewController.bannerView.removeFromSuperview();
I fixed it! Thanks for your help. I had to move the code from the GameViewController to the GameScene for the bannerAd so that I could remove it as soon as the purchase was made. Works perfectly.

How do you preload banner iAds in Swift?

I just integrated iAds into my app and they work perfectly. The only problem is that there is a delay on the page before the ad shows up. I'd like to preload the ads as soon as the app is launched. I have one medium rectangle ad and one regular banner ad (on different views in the app).
Medium rectangle is loaded on viewDidLoad() of ReadingVC.swift like this:
var rectangleAdView = ADBannerView(adType: ADAdType.MediumRectangle)
// Show banner ad
rectangleAdView?.delegate = self
With the following functions:
func bannerViewDidLoadAd(banner: ADBannerView!) {
println("bannerViewDidLoadAd - Ad shown on app")
self.view.addSubview(banner)
self.view.layoutIfNeeded()
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError
error: NSError!) {
banner.removeFromSuperview()
self.view.layoutIfNeeded()
}
The regular banner is loaded on viewDidLoad() of LibraryVC.swift in the same fashion, just with ADAdType.Banner instead of ADAdType.MediumRectangle
How can this be done?
There will always be a bit of a delay because the application has to grab the ads from the iAd CDN. Now, if you have a view that shows before either ReadingVC and LibraryVC, you can always try to load the ads there beforehand. To do this, you'd probably need to create a separate singleton class to hold all of your iAd code, and then access that class from all of the places you need to display or try to preload an iAd.

Swift SpriteKit iAd

I'm developing a game in Swift and I have a little problem that I couldn't solve. I'm working only with scenes, I have no UIViews. The main scene is where the game runs and when the players dies a new scene will be loaded. I want in that scene, where the player dies, to display a menu (which I did) and to display iAd banners. I tried also with UIViewControllers but I couldn't manage it. I want to make it only in SpriteKit and I don't know how. Could anybody help me please?
If you simply want to display an iAd banner then you'll need to do several things. First, import the iAd framework and import iAd the the top of your code. Then, use this function to display the banner. (oh, and adBannerView should be declared as a global variables within your skscene).
func loadAds()->ADBannerView{
adBannerView = ADBannerView(frame: CGRect.zeroRect)
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view!.frame.size.height - adBannerView.frame.size.height / 2)
adBannerView.delegate = self
self.view?.addSubview(adBannerView)
return adBannerView
}
You may also want to include these functions. This one right here runs when the banner cannot load (this will most likely occur due to a network problem).
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
println("Ad cannot load")
self.adBannerView.hidden = true
}
This runs when the banner successfully loads.
func bannerViewDidLoadAd(banner: ADBannerView!) {
println("ad did load.")
self.adBannerView.hidden = false
}

ios iAd loading before displaying

I'm working on a iOS game in swift.
I'm trying to add an interstitial ad.
What I would like to do is when the game is over, displaying an Ad.
After closing it, the user can launch another game.
When the game is over I call this method:
func showFullScreenAd() {
if requestingAd == false {
interstitial = ADInterstitialAd()
interstitial!.delegate = self
requestingAd = true
}
}
func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
if interstitial?.loaded==true{
....}
}
The ad will be displayed when interstitialAdDidLoad is called.
So, between showFullScreenAd() and interstitialAdDidLoad some times we may have several seconds (the time for the ad to load) so the user can click on 'new game' and starts the game.
So, the game will begin and then the ad will be displayed (I'm handling the pause mode also) but it's weird to start the game and to have the ad showing up.
I'm thinking about the following case:
doing
interstitial = ADInterstitialAd()
when loading the game
and when the game is over just show the ad (if available), and doing it again after that.
What do you think about this ?
Thanks.
C.C.
You have to add the ad onto the view as a subview right? So load it and add it to the view when you are ready to. I'm assuming that you're doing it before interstitialAdDidLoad at the moment?

Resources