# Get Started on iOS

## Before You Begin

1. [Create and set up your Chartboost account](/en/monetization/get-started/).
2. Download and review the [Chartboost Sample App](https://github.com/ChartBoost/ios-sdk-example)

<div class="alert alert-info" role="alert">
  <b>Note:</b>
  Due to Apple's sound architecture, managing audio when displaying ads that reproduce sound via WKWebView or AVPlayer can result in audio overlap. Since iOS perceives the application and the SDK as the same audio source, simultaneous playback of the ad's audio track and the application's can occur.
  <br><br>
  Therefore, <b>we recommend that developers implement the necessary logic to pause the application's audio playback before the ad starts and resume it once it has concluded</b>. This handling allows for a more fluid and coherent user experience.
</div>

## Minimum Supported Development Tools

| Software | Version |
| -------- | ------- |
| Minimum Supported iOS Version | 11.0 |
| Minimum Xcode Version | 16.0 |
| Swift | 5.5+ |

## Import the Chartboost Framework

The `ChartboostSDK.xcframework` needs to be imported into your Xcode project.
This can be done via Swift Package Manager, CocoaPods, or manually.

### Swift Package Manager

The Chartboost Monetization SDK is distributed as a binary framework via
[Swift Package Manager](https://www.swift.org/documentation/package-manager/).

**Using Xcode:**

1. In Xcode, select **File > Add Package Dependencies…**.
2. Enter the package repository URL: `https://github.com/ChartBoost/chartboost-monetization-ios-sdk`
3. Add the `ChartboostSDK` library product to your app target.

**Using a `Package.swift` manifest:**

Add the package to your `dependencies`, then add the `ChartboostSDK` product to the target that uses it:

```swift
dependencies: [
    .package(url: "https://github.com/ChartBoost/chartboost-monetization-ios-sdk", from: "9.13.0"),
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: [
            .product(name: "ChartboostSDK", package: "chartboost-monetization-ios-sdk"),
        ]
    ),
],
```

<div class="alert alert-info" role="alert">
  <b>Note:</b> The <code>-ObjC</code> linker flag is required (see <b>Setting Up Chartboost SDK</b>, step 1, below).
  When integrating with Swift Package Manager it must be added to your app target's <b>Other Linker Flags</b> manually.
</div>

### CocoaPods

1. Download and install [CocoaPods](https://guides.cocoapods.org/using/getting-started.html).
2. Open your project’s **Podfile** and add the line `pod 'ChartboostSDK'`.
3. Run `pod install --repo-update` from the command line.

For more information on using CocoaPods, refer to [CocoaPods’ documentation](https://guides.cocoapods.org/using/using-cocoapods).

### Manual Import

1. Download the [iOS Chartboost SDK](https://s3.amazonaws.com/chartboost/sdk/9.13.0/Chartboost-iOS-9.13.0.zip).
2. Unzip the file. Then drag and drop the `ChartboostSDK.xcframework` folder into your Xcode project.
3. Mark it as **Do Not Embed**.
4. Drop the `ChartboostSDKResources.bundle` file and add it into the **Build Phases > Copy Bundle Resources** section.
5. If your project is pure Objective-C, you can add a Swift file or add the following settings to import the swift libraries.
   1. **Add Build Settings** > **Search Paths** >** Library search paths** `$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) $(SDKROOT)/usr/lib/swift`
   2. **Add Build Settings** > **Linking** > **Runpath search paths**` /usr/lib/swift`

If your project is targeting an iOS version 12.4 or earlier, set **Build Settings** > **Always Embed Swift Standard Libraries** to **YES**. 

<div class="alert alert-info" role="alert">
  <b>Pro Tip:</b> Checkmark the <b>Copy items if needed</b> option to create a local copy of the framework for your project. This will help keep your project organized.
</div>

## Setting Up Chartboost SDK

#### 1. Add value `-ObjC` in **Other Linker Flags** under your project’s **Build Settings** for both **Debug** and **Release**.

#### 2. Add a new dictionary with Chartboost’s **`SKAdNetworkIdentifier`** value `f38h382jlk.skadnetwork` as well as additional identifiers of other Chartboost Demand Partners to the `SKAdNetworkItems` array in your `Info.plist`.
- This is a new required step for iOS 14 integrations. See [iOS 14 Preparation](/en/monetization/integrate/ios/upgrading-the-sdk/) to learn more.
- The full list of Chartboost required `SKAdNetwork` IDs can be found here in [XML](https://a3.chartboost.com/skadnetworkids.xml) and [JSON](https://a3.chartboost.com/skadnetworkids.json) formats.
- We recommend enabling warning-level logs in order to have our most up-to-date `SKAdNetwork ID` list.

```xml
<key>SKAdNetworkItems</key>
<array>
  <dict>
    <key>SKAdNetworkIdentifier</key>
    <string>f38h382jlk.skadnetwork</string>
  </dict>
</array>
```

#### 3. Add the following import header to your `AppDelegate.m` file:

<ul class="tab" data-tab="8e1b410a-6265-4d0d-aa49-588211af2654" data-name="AppDelegate">
  
      <li class="active">
          <a href="#">swift </a>
      </li>
  
      <li>
          <a href="#">objective-c </a>
      </li>
  
</ul>
<ul class="tab-content" id="8e1b410a-6265-4d0d-aa49-588211af2654" data-name="AppDelegate">
  
      <li class="active">
<div class="language-swift highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">import</span> <span class="kt">ChartboostSDK</span>
</code></pre></div></div>
</li>
  
      <li>
<div class="language-objectivec highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#import &lt;ChartboostSDK/Chartboost.h&gt;
</span></code></pre></div></div>
</li>
  
</ul>


#### 4. Initialize Chartboost in your `didFinishLaunchingWithOptions` method.
- `start(withAppID:appSignature:completion:)` must always be called on bootup, regardless of any other actions your app takes.
- Publishers should call the `addDataUseConsent` API from the Chartboost SDK and pass in the appropriate value for whether **consent exists**, **does not exist**, or **is unknown**. Publishers are required by the Terms of Service to obtain consent from their users before Chartboost can process any personal data and pass it to the Chartboost SDK via the above method. This method should be called before `start(withAppID:appSignature:completion:)` if possible.  
 Review our [privacy methods](/en/monetization/integrate/ios/sdk-privacy-methods/) and [behavioral targeting](/en/faq/coppa/) documentation for more information.

<ul class="tab" data-tab="5f656298-34b3-4526-8ef2-381bf76f83c1" data-name="didFinishLaunchingWithOptions">
  
      <li class="active">
          <a href="#">swift </a>
      </li>
  
      <li>
          <a href="#">objective-c </a>
      </li>
  
</ul>
<ul class="tab-content" id="5f656298-34b3-4526-8ef2-381bf76f83c1" data-name="didFinishLaunchingWithOptions">
  
      <li class="active">
<div class="language-swift highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">func</span> <span class="nf">application</span><span class="p">(</span><span class="n">_</span> <span class="nv">application</span><span class="p">:</span> <span class="kt">UIApplication</span><span class="p">,</span> <span class="n">didFinishLaunchingWithOptions</span> <span class="nv">launchOptions</span><span class="p">:</span> <span class="p">[</span><span class="kt">UIApplication</span><span class="o">.</span><span class="kt">LaunchOptionsKey</span><span class="p">:</span> <span class="kt">Any</span><span class="p">]?)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span> <span class="p">{</span>
        <span class="kt">Chartboost</span><span class="o">.</span><span class="nf">start</span><span class="p">(</span><span class="nv">withAppID</span><span class="p">:</span> <span class="s">"YOUR_CHARTBOOST_APP_ID"</span><span class="p">,</span>
                         <span class="nv">appSignature</span><span class="p">:</span> <span class="s">"YOUR_CHARTBOOST_APP_SIGNATURE"</span><span class="p">)</span> <span class="p">{</span> <span class="n">error</span> <span class="k">in</span>
                            <span class="k">let</span> <span class="nv">vc</span> <span class="o">=</span> <span class="k">self</span><span class="o">.</span><span class="n">window</span><span class="p">?</span><span class="o">.</span><span class="n">rootViewController</span> <span class="k">as?</span> <span class="kt">ViewController</span>
                            <span class="n">vc</span><span class="p">?</span><span class="o">.</span><span class="nf">log</span><span class="p">(</span><span class="nv">message</span><span class="p">:</span> <span class="n">error</span> <span class="o">==</span> <span class="kc">nil</span> <span class="p">?</span> <span class="s">"Chartboost initialized successfully!"</span> <span class="p">:</span> <span class="s">"Chartboost failed to initialize."</span><span class="p">)</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="kc">true</span>
    <span class="p">}</span>
</code></pre></div></div>
</li>
  
      <li>
<div class="language-objectivec highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">-</span> <span class="p">(</span><span class="n">BOOL</span><span class="p">)</span><span class="nf">application</span><span class="p">:(</span><span class="n">UIApplication</span> <span class="o">*</span><span class="p">)</span><span class="nv">application</span> <span class="nf">didFinishLaunchingWithOptions</span><span class="p">:(</span><span class="n">NSDictionary</span> <span class="o">*</span><span class="p">)</span><span class="nv">launchOptions</span> <span class="p">{</span> 
<span class="c1">// Initialize the Chartboost library    </span>
    <span class="p">[</span><span class="n">Chartboost</span> <span class="nf">startWithAppID</span><span class="p">:</span><span class="s">@"YOUR_CHARTBOOST_APP_ID"</span>
        <span class="nl">appSignature:</span><span class="s">@"YOUR_CHARTBOOST_APP_SIGNATURE"</span>
        <span class="nl">completion:</span><span class="o">^</span><span class="p">(</span><span class="n">CHBStartError</span> <span class="o">*</span> <span class="n">_Nullable</span> <span class="n">error</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span> 
            <span class="n">NSLog</span><span class="p">(</span><span class="s">@"Chartboost SDK initialization finished with error %@"</span><span class="p">,</span> <span class="n">error</span><span class="p">);</span> 
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> 
            <span class="n">NSLog</span><span class="p">(</span><span class="s">@"Chartboost SDK initialization finished with success"</span><span class="p">);</span> 
        <span class="p">}</span> 
        <span class="p">}];</span> 
    <span class="k">return</span> <span class="nb">YES</span><span class="p">;</span> 
<span class="p">}</span>
</code></pre></div></div>
</li>
  
</ul>


#### 5. Add your app ID and app signature.
- Replace `YOUR_CHARTBOOST_APP_ID` and `YOUR_CHARTBOOST_APP_SIGNATURE` with your app ID and app signature
- Chartboost App ID is a unique App identifier in our systems, therefore it is **required to use a different Chartboost App ID per each app**

#### 6. (If applicable) Add Google EDM dependencies for Unity
To ensure iOS resources are embedded correctly on SDK versions prior to 9.11.0, Apps built on Unity should add the Chartboost Monetization iOS SDK to all targets in their Google EDM dependencies for their Unity plugin using the following snippet: `<iosPod name="AppLovinMediationChartboostAdapter" version="9.13.0.0" addToAllTargets="true"/>`.

## To Show a Static or Video Interstitial Ad

Interstitial ads need to be cached before being displayed. Use the method `[interstitial cache]`; to cache an interstitial ad.

Once the interstitial ad is cached you can display it using the method` [interstitial showFromViewController:self]`;:

<ul class="tab" data-tab="0dba1c40-96d1-4648-b5a8-e2e83b9727c8" data-name="CHBShowErrorCodeNoCachedAd">
  
      <li class="active">
          <a href="#">swift </a>
      </li>
  
      <li>
          <a href="#">objective-c </a>
      </li>
  
</ul>
<ul class="tab-content" id="0dba1c40-96d1-4648-b5a8-e2e83b9727c8" data-name="CHBShowErrorCodeNoCachedAd">
  
      <li class="active">
<div class="language-swift highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="n">interstitial</span><span class="o">.</span><span class="nf">show</span><span class="p">(</span><span class="nv">from</span><span class="p">:</span> <span class="k">self</span><span class="p">)</span>
</code></pre></div></div>
</li>
  
      <li>
<div class="language-objectivec highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="p">[</span><span class="n">interstitial</span> <span class="nf">showFromViewController</span><span class="p">:</span><span class="n">self</span><span class="p">];</span> 
</code></pre></div></div>
</li>
  
</ul>


## To Show a Rewarded Video Ad

Rewarded ads need to be cached before being displayed. Use the method `[rewarded cache]` to cache a rewarded ad.

Once the rewarded ad is cached you can display it using the method `[rewarded showFromViewController:self]`:

<ul class="tab" data-tab="b77587d0-d8f5-447d-9e19-cf87574d3231" data-name="isCached">
  
      <li class="active">
          <a href="#">swift </a>
      </li>
  
      <li>
          <a href="#">objective-c </a>
      </li>
  
</ul>
<ul class="tab-content" id="b77587d0-d8f5-447d-9e19-cf87574d3231" data-name="isCached">
  
      <li class="active">
<div class="language-swift highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="n">rewarded</span><span class="o">.</span><span class="nf">show</span><span class="p">(</span><span class="nv">from</span><span class="p">:</span> <span class="k">self</span><span class="p">)</span>
</code></pre></div></div>
</li>
  
      <li>
<div class="language-objectivec highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="p">[</span><span class="n">rewarded</span> <span class="nf">showFromViewController</span><span class="p">:</span><span class="n">self</span><span class="p">];</span> 
</code></pre></div></div>
</li>
  
</ul>


## To Show a Banner Ad

Banner ads need to be cached before being displayed. 

Use the following method to cache a banner ad:
<ul class="tab" data-tab="90c0635f-cb2a-44b9-a82c-2df7e981dcf3" data-name="cacheBanner">
  
      <li class="active">
          <a href="#">swift </a>
      </li>
  
      <li>
          <a href="#">objective-c </a>
      </li>
  
</ul>
<ul class="tab-content" id="90c0635f-cb2a-44b9-a82c-2df7e981dcf3" data-name="cacheBanner">
  
      <li class="active">
<div class="language-swift highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">banner</span><span class="o">.</span><span class="nf">cache</span><span class="p">()</span>
</code></pre></div></div>
</li>
  
      <li>
<div class="language-objectivec highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="n">banner</span> <span class="nf">cache</span><span class="p">];</span> 
</code></pre></div></div>
</li>
  
</ul>


Then, use the following method to show a banner ad:
<ul class="tab" data-tab="5f571696-922c-475b-bd7e-c0b2faf90c94" data-name="showBanner">
  
      <li class="active">
          <a href="#">swift </a>
      </li>
  
      <li>
          <a href="#">objective-c </a>
      </li>
  
</ul>
<ul class="tab-content" id="5f571696-922c-475b-bd7e-c0b2faf90c94" data-name="showBanner">
  
      <li class="active">
<div class="language-swift highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">banner</span><span class="o">.</span><span class="nf">show</span><span class="p">(</span><span class="nv">from</span><span class="p">:</span> <span class="k">self</span><span class="p">)</span>
</code></pre></div></div>
</li>
  
      <li>
<div class="language-objectivec highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="n">banner</span> <span class="nf">showFromViewController</span><span class="p">:</span><span class="n">self</span><span class="p">];</span>
</code></pre></div></div>
</li>
  
</ul>


## Testing Your SDK Integration

1. Build and run your project from Xcode on a device or Simulator.
2. Use [Test Mode](/en/monetization/charles-web-proxy/) to see if test ads show up.

## SDK Configuration Methods

These methods will allow you to access Chartboost SDK functionality and settings.
```
// Control how much information is logged in the console
+ (void)setLoggingLevel:(CBLoggingLevel)loggingLevel;
```

