mildog8
mildog8

Reputation: 2154

How to integrate Chartboost IOS SDK with Swift

I am trying to integrate the Chartboost IOS SDK with Swift. I have followed all the instructions on the Chartboost IOS Integration page https://answers.chartboost.com/hc/en-us/articles/201220095-iOS-Integration and have created a bridging header to use the framework in my swift project.

BridgingHeader.h

#import <Chartboost/Chartboost.h>
#import <Chartboost/CBNewsfeed.h>
#import <CommonCrypto/CommonDigest.h>
#import <AdSupport/AdSupport.h>

My BridgingHeader.h file is loacated in my project root directory https://i.sstatic.net/tl6kY.png and I have followed the necessary steps to add the BridgingHeader.h to my Build Settings https://i.sstatic.net/kM4Tq.png but when I run the project I get 52 errors like -> https://i.sstatic.net/RZjRI.png. Why am I getting these errors and how do I get rid of them?

Upvotes: 2

Views: 3090

Answers (4)

NSDeveloper
NSDeveloper

Reputation: 1

This issue is how to import.

You can make objC code and bridge.h, to shows in your code

[Chartboost showInterstitial:CBLocationHomeScreen];

For swift

Chartboost.showInterstitial(CBLocationHomeScreen)

i wish that help you

Upvotes: 0

Guru
Guru

Reputation: 22042

Swift Chartboost Code, Add it in AppDelegate Class :

func applicationDidBecomeActive(application: UIApplication) 
{        
    let kChartboostAppID = "5472ef8f04b01601a1a5814c";
    let kChartboostAppSignature = "5b6222426e68cda48669a1d4d8246d4c3d20db9c";

    Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self);
    Chartboost.cacheMoreApps(CBLocationHomeScreen)
}

class func showChartboostAds()
{
     Chartboost.showInterstitial(CBLocationHomeScreen);
}

func didFailToLoadInterstitial(location :String!, withError error: CBLoadError)
{

}

func didDismissInterstitial(location :String! )
{
        if(location == CBLocationHomeScreen)
        {
            Chartboost.cacheInterstitial(CBLocationMainMenu)
        }
        else if(location == CBLocationMainMenu)
        {
            Chartboost.cacheInterstitial(CBLocationGameOver)
        }
        else if(location == CBLocationGameOver)
        {
            Chartboost.cacheInterstitial(CBLocationLevelComplete)
        }
        else if(location == CBLocationLevelComplete)
        {
            Chartboost.cacheInterstitial(CBLocationHomeScreen)
        }
 }

Calling Syntax:

   AppDelegate.showChartboostAds()

Upvotes: 0

user3048652
user3048652

Reputation:

Adding onto the top answer said above try adding both

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Chartboost/Chartboost.h>

to your BridgingHeader.h File

and make sure they are both above the

#import <Chartboost/Chartboost.h>

as shown above

Upvotes: 0

Connor
Connor

Reputation: 64644

It looks like the headers require UIKit and Foundation. Add this line at the top of your bridging header.

#import <UIKit/UIKit.h>

Also, have you made sure your bridging header is in the project's root in the file system? The hierarchy of Xcode's Project Navigator isn't necessarily the same as the file system.

It's looking for the header in /Users/andrew/Documents/dev/ios/Protect Paigridge/ Open finder and make sure that the header is in that directory. Xcode may have created it a level deeper where the rest of your code files are. If that's the case, you can edit entry in Build Settings or move the file.

Upvotes: 4

Related Questions