rastislv
rastislv

Reputation: 320

iOS with custom GADRewardBasedVideoAd class crash

I use Google Ads in my app. Because of my purpose, I created custom.

GADRewardBasedVideoAd class. So my code looks like this:

enum AdState {
    case rewarded
    case loaded
    case unknown
    case error
}

class VideoAd: GADRewardBasedVideoAd {
    var adState: AdState = .unknown
}

And some ViewController:

class ViewController: UIViewController {
  let rewardAddNewsAd = VideoAd()

 ...

  rewardAddNewsAd.delegate = self
}

In the line of code where I set delegate app crash because of

[App.VideoAd setDelegate:]: unrecognized selector sent to instance 0x281c7fd20

If I change rewardAddNewsAd on class GADRewardBasedVideoAd and not my custom subclass everything works fine.

This code was working until Google updated GAD to the last version.


I am using Swift 4.1

Upvotes: 0

Views: 152

Answers (2)

rastislv
rastislv

Reputation: 320

I used again not the singleton, but I did not use my subclass for GADRewardBasedVideoAd. For now, it was working. My point was I was getting different "coins" for each object.

Upvotes: 0

Ilya Kharabet
Ilya Kharabet

Reputation: 4621

Maybe this is a bug, but as described in official site, GADRewardBasedVideoAd has a singleton design and you should not create your own subclasses. Use GADRewardBasedVideoAd.shared to access an instance of GADRewardBasedVideoAd class.

As an option, you can store the AdState somewhere outside VideoAd. For example, in ViewController.

Upvotes: 1

Related Questions