Get Started with Avocarrot

Overview

Examples

Android

Overview

- Native Ads

List/Feed

Custom

- Standard IAB Formats

Banner

Interstitial

Video

- Others

Troubleshooting

Admob Android Adapter

Mopub Android Adapter

DFP Android Adapter

iOS

Overview

- Native Ads

List/Feed

Custom

- Standard IAB Formats

Banner

Interstitial

Video

- Others

Troubleshooting

- Adapters

Admob iOS Adapter

Mopub iOS Adapter

DFP iOS Adapter

API Documentation

Reporting API

Help

Supported Networks & Ad Types

General

Earnings

Payments and Accounting

Integration

Reporting

Mediation Network Optimization

Legal and Privacy

Updates

SDK Change Log

Android Change Log

iOS Change Log

Custom

Updated 4 days ago ​by Derek Lim

 Overview

This tutorial helps you setup Custom ads in your iOS app and receive your first Avocarrot Native ad.


Prerequisites

Create a  Custom ad unit from your app on Avocarrot Dashboard 

Requirements & Dependencies

  • Target iOS 8.0 or higher

Setup SDK

Avocarrot iOS SDK supports iOS 8.0 or higher.

You can add AvocarrotSDK to your project using Cocoapods  (recommended) or manually

Note: If you don’t have pods in your project, set them up using the Getting Started guide
  1. Add pod ‘avocarrot-ios-sdk/Core’ to your Podfile to integrate it to your project
  2. Add the ad types you require to your Podfile:
    pod 'avocarrot-ios-sdk/NativeAssets'

We also have sample code available at our GitHub repository.

Manual Avocarrot SDK integration guide

  1. Add the following SDK files to your project (required)
    Ad type Frameworks
    Custom AvocarrotCore.framework, AvocarrotNativeAssets.framework
  2. Add -ObjC flag to project settings (Other Linker Flags property)  

    Note: If your app can’t use -ObjC flag just add -force_load $(PROJECT_DIR)/Pods/avocarrot-ios-sdk/AvocarrotSDK.framework/Versions/Current/AvocarrotSDK flag to Other Linker Flags

  3. Required system libraries for all libs

    The SDK with adapters uses the following system frameworks and libraries. You can set flag “Link Frameworks automatically” to YES otherwise you should add following system frameworks and libraries to your project manually:

    WebKit

    Security

    QuickLook

    MobileCoreServices

    CoreText

    AssetsLibrary

    Foundation

    CoreData

    Social

    MessageUI

    MediaPlayer

    EventKit

    EventKitUI

    QuartzCore

    CoreMedia

    CFNetwork

    SystemConfiguration

    CoreGraphics

    StoreKit

    CoreTelephony

    AVFoundation

    AdSupport

    AudioToolbox

    UIKit

    libxml2

    libsqlite3

    libz

Warning: Some Xcode versions support new settings only after the Xcode reboot. This also cleans the Xcode cache and remedies other problems.

TO DO list if you have a linking problem:

  • Clean Build
  • Restart Xcode
  • Delete your DerivedData folder in ~/Library/Developer/Xcode/DerivedData
  • Restart the computer

ATS settings in iOS 9.0 and greater

Since the Avocarrot SDK uses 3rd party networks to load ads and we have no control over these networks loading their content via https, you should disable ATS for your application to ensure the Avocarrot SDK behaves as intended. To disable ATS add the following settings to your application Info.plist file:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key><true/>
    <key>NSAllowsArbitraryLoadsForMedia</key><true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key><true/>
</dict>

Setup Custom Ads

Custom Ads are raw ad data without any pre-defined wrapping UI. We only request the container of this data for event registration.
The layout for a custom ad is configured by developers with the help of the Interface Builder (creating .xib file) or manual creation of UI controls in code.
Use the following methods in your UIViewController subclass:

func loadNativeAd(withAdUnitId adUnitId: String,
                  success: @escaping (AVONativeAssets) -> UIView?,
                  failure: ((AVOError) -> ()))?)
- (void)loadNativeAdWithAdUnitId:(NSString *_Nonnull)adUnitId
        success:(UIView * _Nullable (^ _Nonnull)(AVONativeAssets *_Nonnull nativeAd))success
        failure:(void (^ _Nullable)(AVOError *_Nonnull error))failure;

The following method performs asynchronous downloading: raw native data without downloading linked resources and requests a container view for this data.

There is a common algorithm to use when implementing a custom ad:

  1. Create your own subclass of UIView with any name (MyNativeBannerView for example) which will be used as ad view container.
  2. Render the other controls such as labels, buttons and image views, in the ad view container.
  3. Call loadNativeAdWithAdUnitId: etc with the required parameters, where the adUnitId is your private advertising space ID. Success block will be called when the native ad is successfully downloaded.
    Method returns the raw data object AVONativeAssets and requests your ad container where the ad will be rendered (required for registration of clicks and impressions), you can register ad container for interaction late by using this method of AVONativeAssets:
    - (instancetype _Nonnull)registerViewForInteraction:(nonnull UIView *)view forClickableSubviews:(nullable NSArray<UIView *> *)subviews, failure will be called when the native ad download fails, and returns AVOError
  4. Show the ad container on the screen.

For example:

import AvocarrotNativeAssets
...
AvocarrotSDK.shared.loadNativeAd(withAdUnitId: "YOUR_CUSTOM_AD_UNIT_ID",
                 success: { [unowned self] (ad: AVONativeAssets) -> UIView? in
                        let containerView = CustomNativeView()
                        containerView.fillWithNativeAd(ad)
                        ad.onClick({
                            print("Clicked")
                        }).onImpression({
                            print("Impressed")
                        }).onLeftApplication({
                            print("Left application")
                        }).registerView(forInteraction: containerView, forClickableSubviews: nil)
                        self.view.addSubview(containerView)
                        return containerView
                 }) { (error) in
                        print("Native ad loading error: \(error.localizedDescription)")
}
#import <AvocarrotNativeAssets/AvocarrotSDK+AVONativeAssets.h>
...
__weak typeof(self) weakSelf = self;
[AvocarrotSDK.sharedSDK loadNativeAdWithAdUnitId:@"YOUR_CUSTOM_AD_UNIT_ID"
                     success:^UIView * _Nonnull(AVONativeAssets * _Nonnull nativeAd) {
                            CustomNativeView *nativeView = [CustomNativeView new];
                            [nativeView fillWithNativeAd:nativeAd];
                            [[[[nativeAd onImpression:^{
                                NSLog(@"Ad Impressed");
                            }] onClick:^{
                                NSLog(@"Ad Clicked");
                            }] onLeftApplication:^{
                                NSLog(@"Left application");
                            }] registerViewForInteraction:nativeView forClickableSubviews:nil];
                            [weakSelf.view addSubview:nativeView];
                            return nativeView;
                     } failure:^(AVOError * _Nonnull error) {
                            NSLog(@"Native ad loading error: %@", [error localizedDescription]);
}];

To process custom native ad events, you should implement blocks. The following is available:

MethodDescription
- (instancetype _Nonnull)onImpression:(nullable void (^)(void))impressionCalled when ad impression has been counted.
- (instancetype _Nonnull)onClick:(nullable void (^)(void))clickCalled when ad click has been counted.
- (instancetype _Nonnull)onLeftApplication:(nullable void (^)(void))leftApplicationCalled when application has been left after click.

Mediation

If you want you can enable the mediation feature of Avocarrot and receive ads from 3rd party providers. You can follow the bellow steps to start mediating demand partners through Avocarrot.
If you’re already integrated with a demand buyer,  It is not mandatory to remove all SDKs, but we would recommend it in order to ensure a seamless and coherent integration with Avocarrot.
  1. Ensure pod ‘avocarrot-ios-sdk/Core’ is added to your Podfile to integrate it to your project
  2. Ensure the following line has been added:
    pod 'avocarrot-ios-sdk/NativeAssets'
    
  3. To add networks individually, add only the corresponding lines for each network

    NetworkLine
    Admobpod 'avocarrot-ios-sdk/NativeAssetsAdapters/GoogleMobileAdsAdapter'
    Facebookpod 'avocarrot-ios-sdk/NativeAssetsAdapters/FBAudienceAdapter'
    Applovinpod 'avocarrot-ios-sdk/NativeAssetsAdapters/AppLovinAdapter'
    InLocopod 'avocarrot-ios-sdk/NativeAssetsAdapters/InLocoAdapter'
  4. To add all networks available use the following line: (Optional)
    pod 'avocarrot-ios-sdk/NativeAssetsAdapters'

We also have sample code available at our GitHub repository.

Manual Avocarrot SDK integration guide

  1. Check that the following frameworks are added into your project:
    Ad type Frameworks
    Custom AvocarrotCore.framework, AvocarrotNativeAssets.framework
  2. To show native ads from client-side mediated networks in your application you need to add:
  1. For each added external ad network from the section above you should add the SDK adapter for this network for each ad type from the Adapters folder. Just add the necessary adapters to the project. 
    NetworkAdapters
    AdmoblibAVOGoogleMobileAdsAdapter-Core.alibAVOGoogleMobileAdsAdapter-Native.a
    Facebook AudiencelibAVOFBAudienceAdapter-Core.alibAVOFBAudienceAdapter-Native.a
    ApplovinlibAVOAppLovinAdapter-Core.alibAVOAppLovinAdapter-Native.a
    InLocolibAVOInLocoAdapter-Core.alibAVOInLocoAdapter-Native.a

Advanced Customization

Go Live!

  1. Remove sandbox If you have received a sample ad then simply disable the Sandbox mode by including the following instruction in your code:
    AvocarrotSDK.testMode = NO
    You should disable Sandbox mode ONLY when you are done with the integration and you are ready to publish your app. It is against Avocarrot's policies to use live ads during development, and doing so could get your Avocarrot account banned.
  2. Test your implementation on real devices with real ads before rolling it out to production. Please make sure that your test device has a sim-card and the 'Limit Ad Tracking' setting is turned off.
  3. Publish your app. You are now ready to upload your app and start making money!Your app will be marked as live once a certain amount of requests has been reached (>100 requests per day). If you have submitted your app in the Google Play/ Apple Store and you can see live ads, then you have nothing to worry about. Just wait until the impressions threshold has been reached and the app will be shown as live in your dashboard as well.
  4. Update payment details  

    Login to your account and update your payment settings.

Was this article useful?