2014-10-12 53 views
2

我正在嘗試將Swift與Chartboost IOS SDK集成。我遵循了Chartboost IOS集成頁面https://answers.chartboost.com/hc/en-us/articles/201220095-iOS-Integration上的所有說明,並創建了一個橋接頭以在我的swift項目中使用該框架。如何將Swift與Chartboost IOS SDK集成

BridgingHeader.h

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

我BridgingHeader.h文件loacated在我的項目的根目錄http://i.imgur.com/DcTcixo.png,我都遵循必要的步驟,將BridgingHeader.h添加到我的構建設置http://i.imgur.com/jvtzs7a.png但是當我運行該項目我得到52錯誤 - >http://i.imgur.com/WCvyooz.png。爲什麼我會收到這些錯誤,我該如何擺脫它們?

回答

4

看起來頭像需要UIKit和Foundation。將此行添加到橋接頭的頂部。

#import <UIKit/UIKit.h> 

此外,你確定你的橋接頭是在項目的文件系統的根? Xcode的Project Navigator的層次結構不一定與文件系統相同。

它正在尋找標題/Users/andrew/Documents/dev/ios/Protect Paigridge/打開查找器並確保該標題在該目錄中。 Xcode可能已經在其他代碼文件所在的位置創建了更深的級別。如果是這種情況,您可以編輯「生成設置」中的條目或移動文件。

+0

剛纔檢查,我的'BridgingHeader.h'文件肯定是'/Users/andrew/Documents/dev/ios/Protect Paigridge /' – theliberalsurfer 2014-10-16 03:08:16

+0

我已經更新了我的答案。 – connor 2014-10-16 10:04:32

+0

@AndrewM爲你做了這項工作? – connor 2014-10-19 01:45:14

0

斯威夫特Chartboost代碼,添加它在AppDelegate類:

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

調用語法:

AppDelegate.showChartboostAds() 
+1

你真的想在堆棧溢出時公開你的應用ID /簽名嗎? – 2015-09-07 07:19:29

+0

嘿 - 我在這裏有一個奇怪的問題,你會看看http://stackoverflow.com/questions/38919940/chartboost-with-swift-interstitial-prefetch-if-not-complete-wait-but-no-a – skyguy 2016-08-12 15:56:53

0

這個問題是如何導入。

您可以objC代碼和bridge.h,以顯示在你的代碼

[Chartboost showInterstitial:CBLocationHomeScreen];

爲SWIFT

Chartboost.showInterstitial(CBLocationHomeScreen)

我希望能夠幫助您

0

添加到上面回答的頂部答案嘗試加入

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

您BridgingHeader.h文件

,並確保它們都在

#import <Chartboost/Chartboost.h> 

以上如上圖所示