Latest 0.1.6
Homepage https://github.com/serinus42/yieldpro.sdk.ios
Platforms ios 9.0
Dependencies YieldPro
Frameworks UIKit
Authors

YieldPro

Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

The minimum iOS version supported is iOS 9.0. You need to use Xcode 9 or newer to compile the framework.

Installation

YieldPro is available through CocoaPods. To install it, simply add the following lines to your Podfile:

pod 'YieldPro'

If you want to provide ads from Google Mobile Ads as a fallback, you also need to add this line to your Podfile:

pod 'YieldProGoogleMobileAds'

Integration

Initialization

Before you use the framework you must initialize it. Your app delegate’s application:didFinishLaunching: method is a good point to do this. This is where you indicate wether you app is directed at children and which fallbacks you want to use.

YPRService.initialize(withChildDirected: false, fallbacks: [])

If you want to see debug logging can you enable this using:

YPRService.enableDebugLogging()

Banners

Banners are loaded per section. First you create a YPRSectionConfig. Listing the slots (using YPRSlotConfig) is optional.

The config is passed to the YPRService which calls a handler that will receive either a list of banner views or an error. The caller should take ownership of the returned banners and insert them in the view hierarchy. You can use the adSlotIdentifier property to determine where the banner should go.

let sectionConfig = YPRSectionConfig(sectionIdentifier: 1306, slots: [
        YPRSlotConfig(adSlotIdentifier: 971, adSizes: [NSValue(cgSize: CGSize(width: 320, height: 50))]),
        YPRSlotConfig(adSlotIdentifier: 972, adSizes: [NSValue(cgSize: CGSize(width: 320, height: 100))])
    ], rootViewController: self, location: nil, customKeyValues: nil)

YPRService.prepareBanners(forSection: sectionConfig) { (banners, error) in
    if let banners = banners {
        // Insert banner
        banners.forEach {
        $0.delegate = self
        self.view.addSubview($0)
    } else if let error = error {
        // Handle error
    }
}

While only banners are returned for which ads were loaded, it may happen that the ad fails to load anyway. To handle this you must implement the YPRBannerViewDelegate protocol and set the delegate on the banners.

extension MyViewController: YPRBannerViewDelegate {

    func bannerViewAdFailed(_ bannerView: UIView & YPRBannerViewProtocol) {
        bannerView.removeFromSuperview()
    }

}

Interstitials

Interstitials are loaded per section for the first slot only. First you create a YPRSectionConfig. Listing the slot (using YPRSlotConfig) is optional.

The config is passed to the YPRService which calls a handler that will receive either an interstitial or an error. The caller should take ownership of the returned interstitial and showing it.

let sectionConfig = YPRSectionConfig(sectionIdentifier: 1313, slots: nil, rootViewController: self, location: nil, customKeyValues: nil)

YPRService.prepareInterstitial(forSection: sectionConfig) { (interstitial, error) in
    if let interstitial = interstitial {
        // Take ownernship and show interstitial
        self.interstitial = interstitial
        interstitial.delegate = self
        interstitial.show()
    } else if let error = error {
        // Handle error
    }
}

Using the delegate you set on the interstitial you can handle releasing the interstitial when it is no longer needed.

extension MyViewController: YPRInterstitialDelegate {

    func interstitialAdFailed(_ interstitial: YPRInterstitialProtocol) {
        self.interstitial = nil
    }

    func interstitialDidClose(_ interstitial: YPRInterstitialProtocol) {
        self.interstitial = nil
    }

}

Fallback

If you want to provide ads from Google Mobile Ads as a fallback, you also need to add this line to your Podfile:

pod 'YieldProGoogleMobileAds'

When you initialize the framework you can provide the fallback. This would look something like this:

let googleFallback = YPRGoogleMobileAdsFallback(applicationID: "ca-app-pub-3940256099942544~1458002511", delegate: self)
#if DEBUG
    googleFallback.testDevices = ["544d166610c0603780582729ed1ac001", "4e41be9f2a016ba8328d02b78c981384"]
#endif
YPRService.initialize(withChildDirected: false, fallbacks: [googleFallback])
#if DEBUG
    YPRService.enableDebugLogging()
#endif

You need to provide a delegate for the YPRGoogleMobileAdsFallback that provides the appropriate ad unit ids. For example:

func googleMobileAdsFallback(_ fallback: YPRGoogleMobileAdsFallback, adUnitIDForBannerInSection sectionIdentifier: Int, adSlot adSlotIdentifier: Int) -> String? {
    return "ca-app-pub-3940256099942544/2934735716"
}

func googleMobileAdsFallback(_ fallback: YPRGoogleMobileAdsFallback, adUnitIDForInterstitialInSection sectionIdentifier: Int, adSlot adSlotIdentifier: Int) -> String? {
    return "/6499/example/interstitial"
}

These samples use the sample application and ad unit ids as recommend by Google. You need to replace this with your own values.

License

See the LICENSE file for more info.

Latest podspec

{
    "name": "YieldProGoogleMobileAds",
    "version": "0.1.6",
    "summary": "YieldPro fallback for Google Mobile Ads",
    "description": "Provides YieldPro fallback for Google Mobile Ads.",
    "homepage": "https://github.com/serinus42/yieldpro.sdk.ios",
    "license": {
        "file": "LICENSE"
    },
    "authors": {
        "Johan Kool": "[email protected]"
    },
    "source": {
        "http": "https://github.com/serinus42/yieldpro.sdk.ios/raw/release/0.1.6/YieldProGoogleMobileAds.zip"
    },
    "platforms": {
        "ios": "9.0"
    },
    "ios": {
        "vendored_frameworks": "YieldProGoogleMobileAds.framework"
    },
    "dependencies": {
        "YieldPro": []
    },
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This