How to integrate Chartboost IOS SDK with Swift

独自空忆成欢 提交于 2019-12-08 02:27:56

问题


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 http://i.imgur.com/DcTcixo.png and I have followed the necessary steps to add the BridgingHeader.h to my Build Settings http://i.imgur.com/jvtzs7a.png but when I run the project I get 52 errors like -> http://i.imgur.com/WCvyooz.png. Why am I getting these errors and how do I get rid of them?


回答1:


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.




回答2:


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




回答3:


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()



回答4:


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



来源:https://stackoverflow.com/questions/26322891/how-to-integrate-chartboost-ios-sdk-with-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!