iosobjective-cxcodeswiftchartboost

Chartboost SDK Swift Integration


I have been trying to integrate the Objective C Chartboost SDK into a Swift project by following the tutorial on their site and adapting it to swift as best I know by using bridging headers etc. Unfortunately when I run the initial AppDelegate code I get a number of errors as seen in the following Screenshot

Image Link:

https://i.sstatic.net/GIrBo.jpg

Then I tried putting @ signs before the strings like in Objective C and that brought a tonne of errors with it too, after a tonne of research I still didn't really find a way to fix this issue but these are the errors given when I try to add the @ sign in the following fashion.

Chartboost.startWithAppId(appId:@"appID", appSignature:@"appSig", delegate: self)

Image Link:

https://i.sstatic.net/WtIuW.jpg

I also tried the following and was greeted with another similar error:

    let kChartboostAppID: NSString = "123"
    let kChartboostAppSignature: NSString = "123"
    Chartboost.startWithAppId(appId:kChartboostAppID, appSignature:kChartboostAppSignature, delegate: self)

But this gives me the following error (similar to the first error):

Cannot convert the expression's type '(appId: NSString, appSignature: NSString, delegate: AppDelegate)' to type '(String!, appSignature: String!, delegate: ChartboostDelegate!) -> Void'

I would be extremely grateful for any assistance as I have been trying to resolve this for a very long time:)


Solution

  • This worked for me...

    1. drop framework into supporting files

    2. add to bridging header

      #import <UIKit/UIKit.h>
      #import <Chartboost/Chartboost.h>
      
    3. Add chartboost delegate to appdelegate.swift

      class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate {
      
    4. in appldelegate didfinishlaunching

      let kChartboostAppID = "appid"
      let kChartboostAppSignature = "appsignature"
      Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self)
      Chartboost.setShouldRequestInterstitialsInFirstSession(false)
      
    5. show ads

      Chartboost.showInterstitial(CBLocationHomeScreen)
      Chartboost.showInterstitial("AnyCusotmTitleID")