Get Started with Glispa Connect

Overview

Examples

Android

Overview

- Native Ads

List/Feed

Custom

- Standard IAB Formats

Banner

Interstitial

Video

- Others

GDPR

Troubleshooting

Admob Android Adapter

Mopub Android Adapter

DFP Android Adapter

iOS

Overview

- Native Ads

List/Feed

Custom

- Standard IAB Formats

Banner

Interstitial

Video

- Others

GDPR

Troubleshooting

- Adapters

Admob iOS Adapter

Mopub iOS Adapter

DFP iOS Adapter

API Documentation

Reporting API

Help

GDPR FAQ

General

Earnings

Payments and Accounting

Integration

Reporting

Legal and Privacy

Updates

SDK Deprecation Schedule

SDK Change Log

Android Change Log

iOS Change Log

Custom

Updated 3 months ago by Derek Lim

 Overview

This tutorial helps you setup Native Custom ads in your iOS app and receive your first Glispa Connect (formerly Avocarrot) Native ad.

Prerequisites

Create a Native Custom ad unit from your app on Glispa Connect Dashboard 

Requirements & Dependencies

  • Target iOS 8.0 or higher

Setup SDK

Glispa Connect iOS SDK supports iOS 8.0 or higher.

You can add Glispa Connect SDK 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 Glispa Connect 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 Glispa Connect 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 Glispa Connect 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>
As the General Data Protection Regulation (GDPR) takes effect on May 25th, 2018 it is required to use the latest GDPR ready SDK and pass your users’ consent as seen here, in order to be up-to-date and compliant.

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.

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 Glispa Connect's policies to use live ads during development, and doing so could get your Glispa Connect 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?