Skip to content

Instantly share code, notes, and snippets.

@ydn
ydn / native_ads.swift
Created June 10, 2015 18:56
Native Ads Swift Example
let nativeAd = FlurryAdNative(space: "ADSPACE");
nativeAd.adDelegate = self;
nativeAd.viewControllerForPresentation = self;
nativeAd.fetchAd();
nativeAd.trackingView = self;
@ydn
ydn / FlurryNativeAdCallbacks.swift
Created June 10, 2015 20:31
Flurry Native Ad integration callbacks
class ViewController: UIViewController, FlurryAdNativeDelegate {
// For instance, the two most frequently used callbacks are:
func adNativeDidFetchAd(nativeAd: FlurryAdNative!){
// The SDK returns this callback for every instance of the native ad fetched
// The FlurryAd object contains all of the ad assets
}
// Informational callback invoked when there is an ad error
func adNative(nativeAd: FlurryAdNative!, adError: FlurryAdError, errorDescription: NSError!){
@ydn
ydn / flurry_native.swift
Last active August 29, 2015 14:22
Flurry native ads swift example (complete)
class ViewController: UIViewController, FlurryAdNativeDelegate {
let nativeAd = FlurryAdNative(space:"ADSPACE");
override func viewDidLoad() {
super.viewDidLoad();
// Assign the FlurryAdNativeDelegate
nativeAd.adDelegate = self;
// UIViewController used for presentation of the full screen after the user clicks on the ad
nativeAd.viewControllerForPresentation = self;
@ydn
ydn / FlurryForPublishers_Banner_Full.swift
Created June 10, 2015 21:42
Banner Ad example (full) with Swift
class ViewController: UIViewController, FlurryAdBannerDelegate {
// Initialize ad space to fetch ads from
let adBanner = FlurryAdBanner(space: "ADSPACE");
override func viewDidAppear(animated: Bool){
super.viewDidAppear(animated);
// Fetch and display banner ad for a given ad space
adBanner.adDelegate = self;
adBanner.fetchAnddisplayAdInView(self.view, viewControllerForPresentation: self);
}
@ydn
ydn / FlurryForPublishers_Banner_sample_alt.swift
Last active August 29, 2015 14:22
Alternate Banner Sample (Full) with Swift
class ViewController: UIViewController, FlurryAdBannerDelegate {
let adBanner = FlurryAdBanner(space: "ADSPACE");
override func viewDidAppear(animated: Bool){
super.viewDidAppear(animated);
adBanner.adDelegate = self;
adBanner.fetchAdForFrame(self.view.frame);
}
// Show whenever delegate is invoked
@ydn
ydn / FlurryAdBannerCallbacks.swift
Created June 10, 2015 21:55
Ad Banner Callbacks (Swift)
class ViewController: UIViewController, FlurryAdBannerDelegate {
// Invoked when an ad is received for the specified bannerAd object
func adBannerDidFetchAd(bannerAd: FlurryAdBanner!) { }
// Invoked when the banner ad is rendered
func adBannerDidRender(bannerAd: FlurryAdBanner!) { }
// Informational callback invoked when an ad is clicked for the specified @c bannerAd object
func adBannerDidReceiveClick(bannerAd: FlurryAdBanner!) { }
@ydn
ydn / FlurryForPublishers_Interstitial.swift
Last active August 29, 2015 14:22
Full-Screen Ads (complete example) with Swift
class ViewController: UIViewController, FlurryAdInterstitialDelegate {
let adInterstitial = FlurryAdInterstitial(space:"ADSPACE");
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated);
adInterstitial.adDelegate = self;
adInterstitial.fetchAd();
}
override func viewDidDisappear(animated: Bool) {
@ydn
ydn / FlurryAdInterstitialCallbacks.swift
Created June 10, 2015 22:24
Flurry Full-Screen Ad Integration callbacks (Swift)
class ViewController: UIViewController, FlurryAdInterstitialDelegate {
func adInterstitialDidFetchAd(interstitialAd: FlurryAdInterstitial!) {
// You can choose to present the ad as soon as it is received
interstitialAd.presentWithViewController(self);
}
// Invoked when the interstitial ad is rendered
func adInterstitialDidRender(interstitialAd: FlurryAdInterstitial!) {
@ydn
ydn / FlurryAdsTargetingExamples.swift
Created June 10, 2015 23:04
Configure Ad Serving (Swift)
// Example of enabling the test mode
{
let adInterstitial = FlurryAdInterstitial(space:"ADSPACE");
adInterstitial.adDelegate = self;
let adTargeting = FlurryAdTargeting();
adTargeting.testAdsEnabled = true;
adInterstitial.targeting = adTargeting;
adInterstitial.fetchAd();
}
@ydn
ydn / Flurry_event_with_parameters.swift
Created June 10, 2015 23:13
Flurry Event with Parameters (Swift Example)
// Capture the author info & user status
let articleParams = ["Author": "John Q", "User_Status": "Registered"];
Flurry.logEvent("Article_Read", withParameters: articleParams);