Integrate Millennial Media Ads in a Swift app

178 views Asked by At

I am currently developing an iOS app in Swift 2.0 and decided to use Millennial Media for their Ads. All their documentation refers to Objective-C codes and, although it's not much code at all, I cannot figure out how to port them over Swift.

I tried to search on StackOverflow and on Google but couldn't find anything at all.

I am trying to port the following:

Thank you.

2

There are 2 answers

0
Luca De Angelis On BEST ANSWER

I solved it by integrating the Google AdMob mediation adapter. Once integrated, everything is easily managed via the Google backend.

0
Michelle On

The following code worked for me in Swift.

Make sure you have the following in your bridging header:

#import <MMAdSDK/MMAdSDK.h>

Make sure to include the delegate in your class header:

class MyClass : UIViewController, MMInterstitialDelegate {

Declare your ad as a var:

var interstitialAd = MMInterstitialAd(placementId: "123456")

Call the following inside your viewDidLoad() method:

   interstitialAd?.delegate = self
   interstitialAd?.load(nil)

Use the following to display the Ad:

if ((interstitialAd?.ready) != nil) {
    interstitialAd?.showFromViewController(self)
}