Skip to content

Commit 3284543

Browse files
committed
Added support for AppLovin advertisements. Still a work in progress: the ads are below the table view on the iPad version right now, but seem to not fit to the correct size.
1 parent 166550b commit 3284543

17 files changed

+836
-1
lines changed

ALAd.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// AppLovinAd.h
3+
// sdk
4+
//
5+
// Created by Basil on 2/27/12.
6+
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "ALAdSize.h"
11+
12+
#import "ALAdSize.h"
13+
14+
/**
15+
* This class represents an ad that has been served from AppLovin server and
16+
* should be displayed to the user.
17+
*
18+
* @author Basil Shikin
19+
* @version 1.0
20+
*/
21+
@interface ALAd : NSObject
22+
23+
@property (strong, nonatomic) NSString * html;
24+
@property (strong, nonatomic) ALAdSize * size;
25+
@property (strong, nonatomic) NSString * destinationUrl;
26+
@property (strong, nonatomic) NSString * clickTrackerUrl;
27+
28+
@end

ALAdDisplayDelegate.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// ALAdDisplayDelegate.h
3+
// sdk
4+
//
5+
// Created by Basil on 3/23/12.
6+
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <UIKit/UIKit.h>
11+
12+
#import "ALAd.h"
13+
/**
14+
* This protocol defines a listener for ad display events.
15+
*
16+
* @author Basil Shikin
17+
* @since 2.0
18+
*/
19+
@class ALAdView;
20+
@protocol ALAdDisplayDelegate <NSObject>
21+
22+
/**
23+
* This method is invoked when the ad is displayed in the view.
24+
* <p>
25+
* This method is invoked on the main UI thread.
26+
*
27+
* @param ad Ad that was just displayed. Guranteed not to be null.
28+
* @param view Ad view in which the ad was displayed. Guranteed not to be null.
29+
*/
30+
-(void) ad:(ALAd *) ad wasDisplayedIn: (UIView *)view;
31+
32+
/**
33+
* This method is invoked when the ad is hidden from in the view. This occurs
34+
* when the ad is rotated or when it is explicitly closed.
35+
* <p>
36+
* This method is invoked on the main UI thread.
37+
*
38+
* @param ad Ad that was just hidden. Guranteed not to be null.
39+
* @param view Ad view in which the ad was hidden. Guranteed not to be null.
40+
*/
41+
-(void) ad:(ALAd *) ad wasHiddenIn: (UIView *)view;
42+
43+
/**
44+
* This method is invoked when the ad is clicked from in the view.
45+
* <p>
46+
* This method is invoked on the main UI thread.
47+
*
48+
* @param ad Ad that was just clicked. Guranteed not to be null.
49+
* @param view Ad view in which the ad was hidden. Guranteed not to be null.
50+
*/
51+
-(void) ad:(ALAd *) ad wasClickedIn: (UIView *)view;
52+
53+
@end

ALAdLoadDelegate.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// ALAdLoadDelegate.h
3+
// sdk
4+
//
5+
// Created by Basil on 3/23/12.
6+
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "ALAd.h"
11+
12+
@class ALAdService;
13+
14+
@protocol ALAdLoadDelegate <NSObject>
15+
16+
-(void)adService:(ALAdService *)adService didLoadAd:(ALAd *)ad;
17+
18+
-(void)adService:(ALAdService *)adService didFailToLoadAdWithError:(int)code;
19+
20+
@end

ALAdService.h

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//
2+
// ALAdService.h
3+
// sdk
4+
//
5+
// Created by Basil on 2/27/12.
6+
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
#import "ALAd.h"
12+
#import "ALAdSize.h"
13+
#import "ALAdLoadDelegate.h"
14+
#import "ALAdDisplayDelegate.h"
15+
#import "ALAdUpdateDelegate.h"
16+
17+
/**
18+
* This is an endpoint name for custom AppLovin URL for tracking
19+
* an ad click:
20+
* <pre>
21+
* applovin://com.applovin.sdk/adservice/track_click
22+
* </pre>
23+
*/
24+
extern NSString * const AlSdkUriTrackClick;
25+
26+
/**
27+
* This is an endpoint name for custom AppLovin URL for forcing
28+
* container to load the next ad:
29+
* <pre>
30+
* applovin://com.applovin.sdk/adservice/next_ad
31+
* </pre>
32+
*/
33+
extern NSString * const AlSdkUriNextAd;
34+
35+
/**
36+
* This is an endpoint name for custom AppLovin URL for forcing
37+
* ad container to close itself:
38+
* <pre>
39+
* applovin://com.applovin.sdk/adservice/close_ad
40+
* </pre>
41+
*/
42+
extern NSString * const AlSdkCloseAd;
43+
44+
/**
45+
* This is an endpoint name for custom landing page that should
46+
* be displayed.
47+
* <pre>
48+
* applovin://com.applovin.sdk/adservice/landing_page/<PAGE_ID>
49+
* </pre>
50+
*/
51+
extern NSString * const AlSdkLandingPage;
52+
53+
/**
54+
* This class represents AppLovin Ad serving service. It is able to provide ads, track clicks and conversions.
55+
* <p>
56+
* An instance of this service could be obtained from {@link AppLovinSdk} object via <code>getAdService()</code>
57+
*
58+
* @author Basil Shikin
59+
* @version 1.0
60+
*/
61+
@interface ALAdService : NSObject
62+
63+
/**
64+
* Fetch next ad. A listener registered using <code>setAdListener()</code> will
65+
* be notified once new ad is available to display.
66+
*
67+
* @param adSize Size of an ad to load. Must not be null.
68+
* @param placement String that identifies ad placement
69+
* @param callback A callback to notify of the fact that the ad is loaded. Must not be null. A reference
70+
* to the callback will be persisted until the ad is loaded.
71+
*/
72+
-(void) loadNextAd: (ALAdSize *) adSize placedAt: (NSString *) placement andNotify: (id<ALAdLoadDelegate>)delegate;
73+
74+
/**
75+
* Track a click on a given ad.
76+
*
77+
* @param ad Advertisement to track. Must not be null. This add should be the one returned from
78+
* <code>ALAdLoadDelegate</code>.
79+
*/
80+
-(void) trackClickOn: (ALAd *) ad;
81+
82+
/**
83+
* Add an observer of updates of advertisemetns of a given size
84+
*
85+
* @param adListener Listener to add
86+
* @param adSize Size of ads that the listener is interested in
87+
*/
88+
-(void)addAdUpdateObserver: (id<ALAdUpdateObserver>) adListener ofSize: (ALAdSize *) adSize;
89+
90+
-(void)removeAdUpdateObserver: (id<ALAdUpdateObserver>) adListener ofSize: (ALAdSize *) adSize;
91+
92+
93+
94+
@end

ALAdSize.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// ALAdSize.h
3+
// sdk
4+
//
5+
// Created by Basil on 2/27/12.
6+
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
12+
/**
13+
* This class defines a size of an ad to be displayed. It is recommended to use default sizes that are
14+
* declared in this class (<code>BANNER</code>, <code>INTERSTITIAL</code>)
15+
*
16+
* @author Basil Shikin
17+
* @version 1.0
18+
*/
19+
@interface ALAdSize : NSObject<NSCopying> {
20+
NSUInteger width;
21+
NSUInteger height;
22+
NSString * label;
23+
}
24+
25+
-(NSUInteger) width;
26+
-(NSUInteger) height;
27+
-(NSString *) label;
28+
29+
-(id)initWith: (NSString *)label;
30+
-(id)initWith: (NSUInteger)width by:(NSUInteger)height;
31+
32+
33+
+(ALAdSize *) sizeBanner;
34+
35+
+(ALAdSize *) sizeInterstitial;
36+
37+
+(ALAdSize *) sizeMRec;
38+
39+
+(ALAdSize *) sizeLeader;
40+
41+
+(NSArray *) allSizes;
42+
43+
@end

ALAdUpdateDelegate.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// ALAdUpdateDelegate.h
3+
// sdk
4+
//
5+
// Created by David Anderson on 10/1/12.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@protocol ALAdUpdateObserver <NSObject>
12+
13+
-(void)adService:(ALAdService *)adService didUpdateAd:(ALAd *)ad;
14+
15+
/**
16+
* Check if this delegate currently accepts ad updates
17+
*/
18+
-(BOOL)canAcceptUpdate;
19+
20+
@end

ALAdView.h

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// ALAdView.h
3+
// sdk
4+
//
5+
// Created by Basil on 3/1/12.
6+
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
#import "ALSdk.h"
12+
#import "ALAdService.h"
13+
14+
@interface ALAdView : UIView<ALAdLoadDelegate>
15+
16+
@property (strong, atomic) id<ALAdLoadDelegate> adLoadDelegate;
17+
@property (strong, atomic) id<ALAdDisplayDelegate> adDisplayDelegate;
18+
19+
@property (strong) NSNumber * autoload;
20+
@property (strong, atomic) ALAdSize * adSize;
21+
@property (strong, atomic) NSString * adPlacement;
22+
23+
@property (strong, atomic) UIViewController * parentController;
24+
25+
/**
26+
* Start loading next advertisement. This method will return immediately. An
27+
* advertisement will be rendered by this view when available.
28+
*/
29+
-(void)loadNextAd;
30+
31+
/**
32+
* Render specified ad.
33+
*
34+
* @param ad Ad to render. Must not be null.
35+
*/
36+
-(void)render:(ALAd *)ad;
37+
38+
/**
39+
* Initialize ad view as a banner.
40+
*/
41+
-(id)initBannerAd;
42+
43+
/**
44+
* Initialize ad view as a MRec.
45+
*/
46+
-(id) initMRecAd;
47+
48+
/**
49+
* Initialize ad view as a banner.
50+
*
51+
* @param sdk Instace of AppLovin SDK to use.
52+
*/
53+
-(id)initBannerAdWithSdk: (ALSdk *)anSdk;
54+
55+
/**
56+
* Initialize ad view as a mrec.
57+
*
58+
* @param sdk Instance of AppLovin SDK to use.
59+
*/
60+
-(id)initMRecAdWithSdk: (ALSdk *)anSdk;
61+
62+
/**
63+
* Initialize ad view with given frame and size
64+
*
65+
* @param frame Ad frame to use.
66+
* @param size Ad size to use.
67+
* @param sdk Instace of AppLovin SDK to use.
68+
*/
69+
- (id)initWithFrame:(CGRect)frame size:(ALAdSize *)aSize sdk:(ALSdk *) anSdk;
70+
71+
@end

0 commit comments

Comments
 (0)