Get Started on iOS

Before You Begin ๐Ÿ”—

  1. Create and set up your Chartboost account.
  2. Download and review the Chartboost Sample App

Integration Compatibility ๐Ÿ”—

The Chartboost SDK runs only on devices with iOS version 11.0 or higher, iPhone 5 or later, iPod 6th generation or later, and iPad 4th generation or later.

  • Apps must be compiled with iOS base SDK higher than v10.0.
  • As of June 1, 2016, Apple requires all submitted apps to support IPv6.
  • iOS 10 is the minimum supported version for Chartboost iOS SDK version 8.3.1 and above. Only earlier versions of the Chartboost iOS SDK retain support for older iOS versions.
  • For iOS 14+ information, see Upgrading the SDK.
  • Macs on M1: Publishers that use older SDK versions, or 8.5.0.2 without CocoaPods, wonโ€™t be able to run their apps on the iOS simulator running on M1 Macs. To fix this, publishers need to go to their Xcode project Build Settings and add Any iOS Simulator SDK with the value arm64 inside Excluded Architectures.
  • Xcode 14.1 is the minimum requirement for publishers when integrating Chartboost Ads SDK 9.0 and above.

Import the Chartboost Framework ๐Ÿ”—

The ChartboostSDK.xcframework needs to be imported into your Xcode project. This can be done via CocoaPods or manually.

CocoaPods ๐Ÿ”—

  1. Download and install CocoaPods.
  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.

Manual Import ๐Ÿ”—

  1. Download the iOS Chartboost SDK.
  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.

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 to learn more.
  • The full list of Chartboost required SKAdNetwork IDs can be found here in XML and JSON formats.
  • We recommend enabling warning-level logs in order to have our most up-to-date SKAdNetwork ID list.
<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: ๐Ÿ”—

  • import ChartboostSDK
    
  • #import <ChartboostSDK/Chartboost.h>
    

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 and behavioral targeting documentation for more information.
  • func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            Chartboost.start(withAppID: "YOUR_CHARTBOOST_APP_ID",
                             appSignature: "YOUR_CHARTBOOST_APP_SIGNATURE") { error in
                                let vc = self.window?.rootViewController as? ViewController
                                vc?.log(message: error == nil ? "Chartboost initialized successfully!" : "Chartboost failed to initialize.")
            }
            return true
        }
    
  • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Initialize the Chartboost library    
        [Chartboost startWithAppId:@"YOUR_CHARTBOOST_APP_ID" 
            appSignature:@"YOUR_CHARTBOOST_APP_SIGNATURE" 
            completion:^(CHBStartError * _Nullable error) { 
            if (error) { 
                NSLog(@"Chartboost SDK initialization finished with error %@", error); 
            } else { 
                NSLog(@"Chartboost SDK initialization finished with success"); 
            } 
            }]; 
        return YES; 
    }
    

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

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];.

  • If an interstitial is tried to be shown but it is not cached yet, the operation will fail and the delegate method didShow:error: will be called with a CHBShowErrorCodeNoCachedAd error.
  • You can handle this error there or preemptively check the isCached property before showing the ad. This property indicates if an ad is ready to be shown.
  • Example:
  • if interstitial.isCached { 
        interstitial.show(from: self)
    }
    
  • if (interstitial.isCached) { 
        [interstitial showFromViewController:self]; 
    }
    

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].

  • If a rewarded ad tries to be shown but is not cached yet, the operation will fail, and the delegate method didShow:error: will be called with a CHBShowErrorCodeNoCachedAd error.
  • You can handle this error there or preemptively check the isCached property before showing the ad. This property indicates if an ad is ready to be shown.

Example:

  • if rewarded.isCached { 
        rewarded.show(from: self)
    }
    
  • if (rewarded.isCached) { 
        [rewarded showFromViewController:self]; 
    }
    

To Show a Banner Ad ๐Ÿ”—

Banner ads need to be cached before being displayed.

Use the following method to cache a banner ad:

  • banner.cache()
    
  • [banner cache]; 
    

Then, use the following method to show a banner ad:

  • banner.show(from: self)
    
  • [banner showFromViewController:self];
    

Testing Your SDK Integration ๐Ÿ”—

  1. Build and run your project from Xcode on a device or Simulator.
  2. Use Test Mode 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;

// Mute/unmute chartboost ads
+ (void)setMuted:(BOOL);