Download & Integrate the Chartboost SDK for iOS Swift

Last Update:

 

Add your mobile game to the Chartboost network with just 10 lines of code!

 

Download SDK How to Integrate
v6.6.1 | How big is the SDK?  

 

Upgrade my current SDK Release Notes

 


 

What's in the box? Our SDK package comes fully loaded with features.

High-quality video ads specially tailored for games to reward your players!

Customizable interstitials that give your players a seamless in-game experience!

A robust analytics suite to target your best possible audience!

View full SDK release notes ▶

 


 

Ready to integrate the Chartboost SDK? Let's do this!

 


 

Before you begin:

Adding the SDK to your Swift games is quick and easy – you just need a few ingredients:

  • A Chartboost account
  • An app in your dashboard
  • The latest SDK
  • An active publishing campaign
  • Apps must be compiled with iOS base SDK v6.0 or higher.
  • As of June 1, 2016, Apple requires that all submitted apps support IPv6.
  • iOS version 6.0 or higher required.
  • iPhone 3GS or later, or iPod 3rd gen. or later, or any iPad model required.
  • The bitcode version in iOS 10 is not backwards-compatible with Xcode v7.3.1. Please upgrade to Xcode v8.0+ to avoid bitcode compatibility errors, or disable bitcode in your Xcode v7.3.1 project.
startWithAppId must always be called during hard and soft bootups within the first few seconds of your app launching, regardless of any other actions or user interaction within your app.

 

Unzip the SDK package and drop the Chartboost Framework into your Xcode project.

Be sure you've also linked these frameworks:

  • StoreKit
  • Foundation
  • CoreGraphics
  • UIKit
PRO TIP: Checkmark the Copy items if needed option. This creates a local copy of the framework for your project, which keeps your project organized.

 

Add a bridging header .h file into your Swift project.

    • Set the .h file in your project's build settings. See the section called "Importing Objective-C into Swift" on the iOS Developers website.
    • In the .h file, add the following:
#import <UIKit/UIKit.h>
#import <Chartboost/Chartboost.h>
#import <CommonCrypto/CommonDigest.h>
#import <AdSupport/AdSupport.h>

 

Initialize Chartboost in your didFinishLaunchingWithOptions method.

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Initialize the Chartboost library
        Chartboost.startWithAppId("YOUR_CHARTBOOST_APP_ID", appSignature: "YOUR_CHARTBOOST_APP_SIGNATURE", delegate: nil)
⚠ You must initialize Chartboost so we can record bootups for your game. If you do not initialize Chartboost, you will not be eligible to run advertising campaigns.
startWithAppId must always be called during hard and soft bootups within the first few seconds of your app launching, regardless of any other actions or user interaction within your app.

 

To show a static or interstitial video ad:

// Show interstitial at location HomeScreen. See Chartboost.h for available location options.
Chartboost.showInterstitial(CBLocationHomeScreen)
We strongly recommend that you cache your interstitials before showing them. Learn more about caching ▶
Prefetched videos (in total) only take up 30-50MB, even when you are using mediation.

 

To show a rewarded video ad:

// Show rewarded video pre-roll message and video ad at location MainMenu. See Chartboost.h for available location options.
Chartboost.showRewardedVideo(CBLocationMainMenu)
      • Chartboost calls should always be made from a main – not background – thread, or these calls may time out!
      • For customized control over how and where ads appear, the Chartboost SDK also offers more features such as caching, delegate methods, and named locations.
We strongly recommend that you cache your interstitials before showing them. Learn more about caching ▶
Prefetched videos (in total) only take up 30-50MB, even when you are using mediation.

 

Add your App ID and App Signature.

Replace YOUR_CHARTBOOST_APP_ID and YOUR_CHARTBOOST_APP_SIGNATURE with your App ID and App Signature. You're almost done!

 

Where can I find my App ID and App Signature?

 


 

Test your integration.

To test the setup, start a publishing campaign, add the app you've been integrating with the SDK to the campaign, then launch the Simulator from Xcode. 

If you can see Chartboost test interstitials where you've called for them in your code, you're good to go! Be sure to disable Test Mode (from the App Settings page) so you can see actual network ads:

 


 

w00t! You just integrated the Chartboost SDK into your app!

Now you can start a campaign ▶

 


 

 

Best Practices

First run experience

It's good practice (as noted in the iOS Human Interface Guidelines) to show interstitials only after the user has played your game for the first time.

You can use the below Chartboost SDK delegate method to prevent interstitials until the second initialization call:

// For Chartboost SDKs v5.0+:
Chartboost.setShouldRequestInterstitialsInFirstSession(false)

Check out more Chartboost SDK features

  • Caching: Speed up load times for ads by storing them locally on devices.
  • Chartboost Video: Add beautiful, high-quality video ads to give players the best in-game experience.
  • Named locations: Fine-tune your campaign targeting and ad frequency from the dashboard.
  • Delegate methods: Gain more control over how your game behaves around ads.
  • SDK configuration methods: Access Chartboost SDK functionality and settings.
  • Post-Install Analytics: For games with in-app purchases. Unlock useful data about players' buying behavior to optimize campaigns or retargeting.
  • Mediation: Show your ads along a waterfall of other top-quality networks.

 

You might also like...