Adcash Swift SDK is an advertising framework written in Swift 3!


Prerequisites

  • ZONE ID(s). You can create them at Adcash website, if you don’t have one yet.
  • Xcode 8.1 or higher
  • Swift 3.0 or higher
  • Project deployment target 8.0 or higher

Third Party Dependencies

Adcash Swift SDK uses Alamofire 4.0 for networking operations. In order to use Adcash Swift SDK, you have to add Alamofire into your project.

Installation

Cocoapods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required.

To integrate Adcash Swift SDK and Alamofire into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'AdcashSwift', '1.0'
    pod 'Alamofire', '~> 4.0'
end

Then, run the following command:

$ pod install

Manual

1. Download the Adcash Swift SDK and unzip it.
2. Right click on your project in the Project Navigator menu install-instructions-2 and select Add Files to “name-of-your-project”:
3. Select the AdcashSwift.framework you just unzipped install-instructions-3 and press Add. Make sure you choose Copy items if needed.
4. Follow Alamofire Installation for adding it into your project.
5. Build and Run. Your project should start without any errors.

Don’t forget to add frameworks as ‘Embedded Frameworks’ in your targets General settings

Implementation of Ads

Banner

1. Import the AdcashSwift module.

 import AdcashSwift

2. (Optional) Set your view controller to conform the AdcashBannerProtocol.

    class YourClass: UIViewController, AdcashBannerProtocol {
      //...
    }
 

3. Declare AdcashBanner variable in your class and initialize it.

   //..
      var banner: AdcashBanner!

      banner = AdcashBanner(zoneID:"your-zone-id", viewController: self)
      banner.translatesAutoresizingMaskIntoConstraints = false
      self.view.addSubview(banner)
      banner.delegate = self // You don't need this if you skipped step 2.

      self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[banner(\(AdcashBannerSize))]|",
                                                                       options: NSLayoutFormatOptions(rawValue: 0),
                                                                       metrics: nil,
                                                                         views: ["banner": banner!]
      ))
      self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[banner]|",
                                                                       options: NSLayoutFormatOptions(rawValue: 0),
                                                                       metrics: nil,
                                                                         views: ["banner": banner!]
      ))
   //..
 

4. Load the AdcashBanner.

    banner.load()

5. (Optional) You can catch status updates from your ad by implementing the optional methods in AdcashBannerProtocol.

If you skipped step 2, you don’t have access to functions below.

     adReceived(banner: AdcashBanner)
     adFailedToReceive(banner: AdcashBanner, error: Error)
     adWillPresentScreen(banner: AdcashBanner)
     adWillDismissScreen(banner: AdcashBanner)
     adWillLeaveApplication(banner AdcashBanner)

Interstitial

1. Import the AdcashSwift module.

 import AdcashSwift

2. (Optional) Set your view controller to conform the AdcashInterstitialProtocol.

    class YourClass: UIViewController, AdcashInterstitialProtocol {
      //...
    }
 

3. Declare AdcashInterstitial variable in your class and initialize it.

  //..
     var interstitial: AdcashInterstitial!

     interstitial = AdcashInterstitial(zoneID:"your-zone-id")
     interstitial.delegate = self // You don't need this if you skipped step 2.
  //..

4. Load the AdcashInterstitial.

   interstitial.load()

5. And present it to the screen.

   interstitial.present(fromVC:self)

6. (Optional) You can catch status updates from your ad by implementing the optional methods in AdcashInterstitialProtocol.

If you skipped step 2, you don’t have access to functions below.

    adReceived(interstitial: AdcashInterstitial)
    adFailedToReceive(interstitial: AdcashInterstitial, error: Error)
    adWillPresentScreen(interstitial: AdcashInterstitial)
    adWillDismissScreen(interstitial: AdcashInterstitial)
    adWillLeaveApplication(interstitial: AdcashInterstitial)

Rewarded

1. Import the AdcashSwift module.

 import AdcashSwift

2.Set your view controller to conform the AdcashRewardedVideoProtocol.

    class YourClass: UIViewController, AdcashRewardedVideoProtocol {
      //...
    }
 

3. Declare AdcashRewardedVideo variable in your class and initialize it.

  //..
     var rewarded: AdcashRewardedVideo!

     rewarded = AdcashRewardedVideo(zoneID:"your-zone-id")
     rewarded.delegate = self
  //..

4. To play the AdcashRewardedVideo, call

   rewarded.playFrom(viewController:self)

5.You can catch status updates from your ad by implementing the optional methods in AdcashRewardedVideoProtocol.

Be aware that ‘rewardedVideoDidComplete’ is required to implement.

    adReceived(rewarded: AdcashRewardedVideo)
    adFailedToReceive(rewarded: AdcashRewardedVideo, error: Error)
    adWillPresentScreen(rewarded: AdcashRewardedVideo)
    adWillDismissScreen(rewarded: AdcashRewardedVideo)
    adWillLeaveApplication(rewarded: AdcashRewardedVideo)
    rewardedVideoDidComplete(rewarded: AdcashRewardedVideo, rewardName: String, rewardAmount: Int) //Required

Native

1. Import the AdcashSwift module.

   import AdcashSwift

2. (Optional) Set your view controller to conform AdcashNativeProtocol.

   class YourClass: UIViewController, AdcashNativeProtocol {
     //...
   }

3. Declare AdcashNative variable in your class and initialize it:

   var native: AdcashNative!

   native = AdcashNative(zoneID:"your-zone-id")
   native.delegate = self // You don't need this if you skipped step 2.

4. After loading, if response is successful, AdcashNative instance will be filled with information about the ad, such as:

Title
Description
Rating
Icon
Image
Action button text

to get these values, you should use provided functions below:

    getAdTitle() -> String?
    getAdDescription() -> String?
    getAdRating() -> String?
    getAdRatingPercentage() -> String?
    getAdIconURL() -> URL?
    getAdImageURL() -> URL?
    getAdButtonText() -> String?

If you call these functions before ad is loaded, you will receive nil values.
5. You can catch status updates from your ad by implementing the optional methods in AdcashNativeProtocol.

    adReceived(native: AdcashNative)
    adFailedToReceive(native: AdcashNative, error: Error)

6. You should also handle clicks and impressions so monetization won’t get affected.
Call the function below when ad is visible on screen:

    trackImpression()

to handle clicks, call:

    openClick()

App Transport Security (ATS)


Click for detailed information
With the release of iOS 9, Apple introduced a new default setting, called App Transport Security (ATS). ATS requires apps to make network connections only over SSL. It also allows specific encryption ciphers, SSL version and key length to be used when creating HTTPS connections.

Therefore, all iOS 9 devices running apps built with Xcode 7 that don’t disable ATS will be affected by this change. When a non-ATS compliant app attempts to serve an ad via HTTP on iOS 9, the following log message appears:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.

While Adcash acknowledges the need for secure connections, our ad network is not ready yet with the compliance of the requirements. Therefore, Adcash iOS SDK will work only by disabling App Transport Security in your `Info.plist`. You can do so by using one of the following two ways depending on your preference:

Disable ATS

Disable ATS for all domains

This is the easiest solution. The only thing you need to do is to add the following configuration in your Info.plist:

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

It should look like this:

Disable ATS for all domains

Disable ATS with some exceptions

Disable ATS for all domains, with some exceptions

Click for detailed information
You may only want ATS to work on domains you specifically know can support it. For example, if you may know that your server supports ATS and you would want things like login calls, and other requests to your server to use ATS, but ad requests to Adcash to bypass ATS requirements.

In this case you should set `NSAllowsArbitraryLoads` to true, then define the URLs that you want to be secure in your `NSExceptionDomains` dictionary. Each domain you wish to be secure should have its own dictionary, and the `NSExceptionAllowsInsecureHTTPLoads` for that dictionary should be set to false.

<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
	<key>NSExceptionDomains</key>
	<dict>
		<key>secure.yourdomain.com</key>
		<dict>
			<key>NSExceptionAllowsInsecureHTTPLoads</key>
			<false/>
		</dict>
	</dict>
</dict>

It should look like this:
Disable ATS for all domains with exceptions

If you do not follow the above instructions for apps built on XCode 7, monetization will be severely impacted as some connections might fail resulting in the ads not rendering.

Support

If you need any help or assistance you can contact us by sending email to mobile@adcash.com.