Search code examples
iosswiftchartboost

Swift: Using Chartboost


I have a few questions about using chartboost in my app with Swift. I do not find their documentation much help as it mostly references Objective-C and when I emailed their support they just sent me back links to the Objective-C code. I need the answers in Swift.

1) How do I detect if the video has been watched or cancelled? Their docs say this is called a reward video and this is the what they provide for code

// Called after a rewarded video has been viewed completely and user is eligible for reward.
- (void)didCompleteRewardedVideo:(CBLocation)location
                  withReward:(int)reward;

2) Where do I put the above function? I have read that it is to be used in the app delegate in the didFinishLaunchingWithOptions section but have also read that I need to create it as an extension so I am slightly confused.

3) Again, what is the swift equivalent for this and where do I implement it:

[Chartboost cacheInterstitial:CBLocationHomeScreen];
[Chartboost cacheRewardedVideo:CBLocationHomeScreen];

4) Once that is implemented, is there a way to see if ads have been cached, if not then cache it.

Apologies for the many questions guys. I do love the fact that I can always reply and turn to stack overflow when I hit a wall.

Thanks in advance.


Solution

  • For 1) and 2) This method is good place to be called in app delegate.But with swift extension is a much better option. Use below syntax to call any app delegate method

        Chartboost.setDelegate(self as! ChartboostDelegate)
    

    3) You can use this syntax for swift

        Chartboost.cacheInterstitial(<#T##location: String!##String!#>) 
        Chartboost.cacheRewardedVideo(<#T##location: String!##String!#>)
    

    4) Similarly to delegate method, you can find method to check if the ads have been cached

    Hope it answer all your question

    Don't forget to add Delegate like this in your appdelegate

     class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate {
    

    and then

       func didCompleteRewardedVideo(_ location: String!, withReward reward: Int32) {
        <#code#>
    }
    

    delegate method delegate method available