Get Started on iOS
Before You Begin ๐
- Create and set up your Chartboost account.
- Download and review the Chartboost Sample App
Therefore, 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. This handling allows for a more fluid and coherent user experience.
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 ๐
- Download and install CocoaPods.
- Open your projectโs Podfile and add the line
pod 'ChartboostSDK'
. - Run
pod install --repo-update
from the command line.
For more information on using CocoaPods, refer to CocoaPodsโ documentation.
Manual Import ๐
- Download the iOS Chartboost SDK.
- Unzip the file. Then drag and drop the
ChartboostSDK.xcframework
folder into your Xcode project. - Mark it as Do Not Embed.
- Drop the
ChartboostSDKResources.bundle
file and add it into the Build Phases > Copy Bundle Resources section. - If your project is pure Objective-C, you can add a Swift file or add the following settings to import the swift libraries.
- Add Build Settings > Search Paths >** Library search paths**
$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) $(SDKROOT)/usr/lib/swift
- Add Build Settings > Linking > Runpath search paths
/usr/lib/swift
- Add Build Settings > Search Paths >** Library search paths**
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 beforestart(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
andYOUR_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 aCHBShowErrorCodeNoCachedAd
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 aCHBShowErrorCodeNoCachedAd
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 ๐
- Build and run your project from Xcode on a device or Simulator.
- 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);