Get Started on iOS

Before You Begin πŸ”—

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

Minimum Supported Development Tools πŸ”—

Software Version
Minimum Supported iOS Version 11.0
Minimum Xcode Version 15.0
Swift 5.0+

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