AdColony Basic – ShiVa Engine

AdColony Basic

Nav Gupta: “AdColony is a premium mobile video advertising network & monetization platform, working with Fortune 100 brands & leading app developers around the world.”

Signup

– Visit http://www.adcolony.com and sign up
– Log in and click on Publishers->Setup New App (Green Button)
– Select your platform and store and give your app a title
– Select your ads, but consider your app’s age rating
– You will be given an Application ID and Secret Key in the middle of the page, save those.

XCode

– Visit http://www.adcolony.com, log in and download the iOS SDK
– Open the download folder and select the Library folder
– Click and drag the AdColonyPublic.h and libAdColony.a file into your main xCode project area – not the Classes folder, but just outside of that
– Click on your project, then on Build Settings. Add the following under Other Linker Flags:

-fobjc-arc
-ObjC

– Click on the Build Phases tab. Under the Link Binary With Libraries section, click and drag the libAdColony.a file so that it is referenced there. You can also hit the + button to find the file as well. Make sure the following frameworks are referenced:

AdSupport.framework	 OPTIONAL
AVFoundation.framework	 OPTIONAL
CFNetwork.framework	 REQUIRED
CoreGraphics.framework	 REQUIRED
CoreMedia.framework	 OPTIONAL
CoreTelephony.framework	 REQUIRED
EventKit.framework	 REQUIRED
EventKitUI.framework	 REQUIRED
MediaPlayer.framework	 REQUIRED
MessageUI.framework	 REQUIRED
QuartzCore.framework	 REQUIRED
StoreKit.framework	 OPTIONAL
SystemConfiguration.framework	REQUIRED

– In the S3DEngine_AppDelegate.h file, add the following code to the Import section:

#import "AdColonyPublic.h"

– At approx. line 12 where it says @interface S3DEngine_AppDelegate : NSObject, we want to add the AdColonyDelegate and AdColonyTakeoverAdDelegate commands in the tag. The function now looks as follows:

@interface S3DEngine_AppDelegate : NSObject 
{
   //Do not change any of the code in here...
}

On a side note, any file you want to use the AdColony video for, you would have to do these same steps to add the AdColony commands in the header file.
– Ad this code to the Import section in S3DEngine_AppDelegate.m (approx. line 7):

#import "AdColonyPublic.h"

– Add the following setup code in the applicationDidFinishLaunching function at the bottom (approx. line 85 after the [viewController.glView playDefaultMovieIfAny];) :

 //AdColony Setup Code
 [AdColony initAdColonyWithDelegate:self];

– Below that function just outside, add the following 3 functions. Replace the AdColony App ID and Zone IDs with your own:

// Provide the AdColony app ID for your application
// This can be retrieved from your account on adcolony.com
-(NSString *)adColonyApplicationID
{
    return @"AD_COLONY_APP_ID"; // AdColony app ID
}
// Provide a dictionary of AdColony zone IDs for all zones in use throughout the app.
// These can be retrieved from your account on adcolony.com
// Slot numbers are arbitrary integers
-(NSDictionary *)adColonyAdZoneNumberAssociation
{
    // Enter zone ID or Slot number below
    return [NSDictionary dictionaryWithObjectsAndKeys:
            @"AD_COLONY_ZONE_ID_OR_SLOT_NUMBER", [NSNumber numberWithInt:1], nil];
}
// Enable helpful console log messages
-(NSString *)adColonyLoggingStatus
{
    return AdColonyLoggingOn;
}

At this point, the ad video will take some time to download from the servers and will NOT DISPLAY until fully downloaded. For this reason, its best to run the command to show video using the applicationDidBecomeActive so that you can guarantee an ad. We will assume that this is how you will do it for this tutorial and so to see the ad you have to actually press the home button on your iOS device, then click on the app again and you will see the video.
– Go down to the applicationDidBecomeActive function and paste the following code to show the video:

[AdColony playVideoAdForZone:@"AD_COLONY_ZONE_ID_OR_SLOT_NUMBER"];

– Save, compile and run your app.

Testing

To test the ad, simply press the home button and then click on the app again to return to it. You should see the AdColony video.
You can now go back and place the video anywhere in the code. Keep in mind that you will have to make sure to add the command for AdColony into the HEADER file as well as @interface S3DEngine_AppDelegate : NSObject (see above) for any file you plan to call the AdColony video from. Failure to do this will result in pointer errors.




Need more answers?

  • slackBanner