如何在Swift中使用Chartboost和Cocoapods ?

时间:2023-01-24 07:25:24

This is my Podfile

这是我Podfile

platform :ios, 8.0
use_frameworks!

pod "ChartboostSDK"
pod "SVProgressHUD"

SVProgressHUD is being turning into a framework, but for some reason Chartboost is not.

SVProgressHUD正在成为一个框架,但由于某种原因,Chartboost不是。

如何在Swift中使用Chartboost和Cocoapods ?

That of course makes the import for Chartboost not working in my code.

当然,这使得Chartboost的导入不能在我的代码中工作。

1 个解决方案

#1


1  

The library ChartboostSDK is not supported for Swift directly using CocoaPods, you need to integrate it manually in the following way:

Swift直接使用CocoaPods不支持library ChartboostSDK,需要以以下方式手工集成:

1.First, unzip the SDK package and drop the Chartboost Framework into your Xcode project. Be sure you've also linked these frameworks:

1。首先,解压缩SDK包并将Chartboost框架放入Xcode项目。确保你也联系了这些框架:

  • StoreKit
  • 更新
  • Foundation
  • 基金会
  • CoreGraphics
  • CoreGraphics
  • UIKit
  • UIKit

2.Then you need to add a Swift bridging header allows you to communicate with your old Objective-C classes from your Swift classes.You will need one if you plan to keep portions of your codebase in Objective-C. You can create it manually like in the following way:

2。然后您需要添加一个Swift桥接头,允许您与您的Swift类中的旧Objective-C类进行通信。如果您打算在Objective-C中保留部分代码基,您将需要一个。您可以按以下方式手动创建:

  1. Add a new file to Xcode (File > New > File), then select “Source” and click “Header File“.

    向Xcode添加一个新文件(文件>新的>文件),然后选择“Source”,点击“Header文件”。

  2. Name your file “YourProjectName-Bridging-Header.h”.

    “YourProjectName-Bridging-Header.h”命名文件。

  3. Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results. Note: If you don’t have a “Swift Compiler – Code Generation” section, this means you probably don’t have any Swift classes added to your project yet. Add a Swift file, then try again.

    导航到项目构建设置,并找到“Swift编译器-代码生成”部分。您可能会发现在搜索框中输入“Swift编译器”来缩小搜索范围会更快。注意:如果您没有“Swift编译器-代码生成”部分,这意味着您可能还没有向项目添加任何Swift类。添加一个Swift文件,然后再次尝试。

  4. Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there. Examples: “ProjectName/ProjectName-Bridging-Header.h” or simply “ProjectName-Bridging-Header.h”.

    在“Objective-C桥接头”旁边,您需要添加头文件的名称/路径。如果文件位于项目的根文件夹中,只需将头文件的名称放在那里。例子:“ProjectName / ProjectName-Bridging-Header。h”或简单的“ProjectName-Bridging-Header.h”。

  5. Open up your newly created bridging header and import your Objective-C classes using #import statements. Any class listed in this file will be able to be accessed from your swift classes.

    打开新创建的桥接头,使用#import语句导入Objective-C类。此文件中列出的任何类都可以从您的swift类中访问。

You bridging header must be have inside the following lines:

您的桥接标头必须包含以下几行:

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

You can read more about the next steps using Charboost in his iOS Integration help manual.

您可以在他的iOS集成帮助手册中阅读有关Charboost的后续步骤。

I hope this help you.

我希望这对你有帮助。

#1


1  

The library ChartboostSDK is not supported for Swift directly using CocoaPods, you need to integrate it manually in the following way:

Swift直接使用CocoaPods不支持library ChartboostSDK,需要以以下方式手工集成:

1.First, unzip the SDK package and drop the Chartboost Framework into your Xcode project. Be sure you've also linked these frameworks:

1。首先,解压缩SDK包并将Chartboost框架放入Xcode项目。确保你也联系了这些框架:

  • StoreKit
  • 更新
  • Foundation
  • 基金会
  • CoreGraphics
  • CoreGraphics
  • UIKit
  • UIKit

2.Then you need to add a Swift bridging header allows you to communicate with your old Objective-C classes from your Swift classes.You will need one if you plan to keep portions of your codebase in Objective-C. You can create it manually like in the following way:

2。然后您需要添加一个Swift桥接头,允许您与您的Swift类中的旧Objective-C类进行通信。如果您打算在Objective-C中保留部分代码基,您将需要一个。您可以按以下方式手动创建:

  1. Add a new file to Xcode (File > New > File), then select “Source” and click “Header File“.

    向Xcode添加一个新文件(文件>新的>文件),然后选择“Source”,点击“Header文件”。

  2. Name your file “YourProjectName-Bridging-Header.h”.

    “YourProjectName-Bridging-Header.h”命名文件。

  3. Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results. Note: If you don’t have a “Swift Compiler – Code Generation” section, this means you probably don’t have any Swift classes added to your project yet. Add a Swift file, then try again.

    导航到项目构建设置,并找到“Swift编译器-代码生成”部分。您可能会发现在搜索框中输入“Swift编译器”来缩小搜索范围会更快。注意:如果您没有“Swift编译器-代码生成”部分,这意味着您可能还没有向项目添加任何Swift类。添加一个Swift文件,然后再次尝试。

  4. Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there. Examples: “ProjectName/ProjectName-Bridging-Header.h” or simply “ProjectName-Bridging-Header.h”.

    在“Objective-C桥接头”旁边,您需要添加头文件的名称/路径。如果文件位于项目的根文件夹中,只需将头文件的名称放在那里。例子:“ProjectName / ProjectName-Bridging-Header。h”或简单的“ProjectName-Bridging-Header.h”。

  5. Open up your newly created bridging header and import your Objective-C classes using #import statements. Any class listed in this file will be able to be accessed from your swift classes.

    打开新创建的桥接头,使用#import语句导入Objective-C类。此文件中列出的任何类都可以从您的swift类中访问。

You bridging header must be have inside the following lines:

您的桥接标头必须包含以下几行:

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

You can read more about the next steps using Charboost in his iOS Integration help manual.

您可以在他的iOS集成帮助手册中阅读有关Charboost的后续步骤。

I hope this help you.

我希望这对你有帮助。