Add Flurry AppCircle to AdWhirl
I have 3 Apps currently running AdWhirl: Hawaiian Words, Hawaiian Names, and Animal Translate Lite.
AdWhirl gives me huge flexibility in switching between multiple Ad Networks (currently using iAd, AdMob, Greystripe, Millennial Media, and InMobi) and House Ads.
I decided that I want to promote my Apps through Flurry's AppCircle, but also earn revenue by advertising with AppCircle too. Since my 3 free Apps already serve ads, adding AppCircle shouldn't effect user experience.
Given the small amount of real estate on an iPhone screen, I wanted the AppCircle ads to display in the same location as the AdWhirl ads, and if possible, not interfere with one another.
I found an elegant solution in AdWhirl's "Custom Events". The remainder of the tutorial will assume that you have AdWhirl installed in an App, and that you have created an account with Flurry, downloaded the Flurry SDK, and created an application within Flurry (Flurry makes this very simple).
Once logged into AdWhirl, click on your App, then click "Add Custom Event" near the top left.
Create a name (I called mine "Flurry App Circle") that will be used within the AdWhirl control panel. Then create a function name (mine is "flurryAppCircle") which will be used in your code. This function name is very important.
Add the Flurry Analytics and Flurry AppCircle folders from the SDK you've downloaded to your Xcode project.
In your AppDelegate.m, add this code at the top:
#import "FlurryAnalytics.h"
#import "FlurryAppCircle.h"
Within your application:didFinishLaunchingWithOptions: method, add this code (substituting the Flurry ID generated:
[FlurryAppCircle setAppCircleEnabled:YES];
[FlurryAnalytics startSession:@"YOUR_KEY_HERE"];
Next, go to the View Controller.h file where your AdWhirlView is set up. Import FlurryAppCircle.h and FlurryAdDelegate.h, and make the view controller a FlurryAdDelegate. I've called my AdWhirlView "adView".
#import "FlurryAppCircle.h"
#import "FlurryAdDelegate.h"
@interface ViewController : UIViewController <AdWhirlDelegate, FlurryAdDelegate> {
AdWhirlView *adView;
}
Finally, add a method with the same function name you used in your AdWhirl Custom Event setup. You can also add the FlurryAdDelegate method "dataUnavailable" that is called when AppCircle data is unavailable, in order to roll-over the ad banner to a different ad.
Create a UIView called "banner" with a Hook (see below), x and y locations at 0, and within your adView. You can also specify the orientation and other features defined in the AppCircle manual. We'll keep it simple for now.
If FlurryAppCircle transmits an ad, we find the size of the ad "adSize". We then create a newFrame based on the adSize and center it in the screen. This code will handle both iPhone and iPad sized Flurry ads. We then set the adView frame to our newFrame and redefine the frame of our banner. This step may seem unnecessary, but I've had Flurry ads delivered with an xLocation of -20 even despite defining the xLoc as 0. This is something Flurry should fix.
Finally, we replace the old ad with our new Flurry ad. If banner is nil, or if the FlurryAppCircle calls the dataUnavailable delegate method, we simply call [adView rollOver] to go to the next available Ad from another network.
The "Hook" name is used by Flurry to identify each individual ad banner. I would suggest using different names for each ad banner, so that you can differentiate which ad banners are more effective.
Voila! This worked perfectly for me. Comment if you have any questions!
If you want to accomplish the same thing in a TableView without covering the TableView contents with the ad, you will need to adjust the frame of the TableView at the same time. Below is the code which is a fairly simple addition to the above example, and can be used in the AdWhirl methods themselves to adjust the TableView when receiving non-Flurry Ads.
