-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdViewController.m
76 lines (62 loc) · 2.68 KB
/
AdViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* AdViewController.m
* AdMob iPhone SDK publisher code.
*
* Sample code. See AdViewController.h for instructions.
*/
#import "AdMobView.h"
#import "AdViewController.h"
@implementation AdViewController
- (void)awakeFromNib {
// If using this object in a nib other than MainWindow.xib, uncomment the following [self retain] line, else this object will be autoreleased
// out of existence -- see http://developer.apple.com/releasenotes/DeveloperTools/RN-InterfaceBuilder/index.html#//apple_ref/doc/uid/TP40001016-SW5
// section "FAQ: What is different about NIB loading in a Cocoa Touch application?"
// You can tell that this is occurring if you never get any calls back to -didReceiveAd: or -didFailToReceiveAd:.
[self retain];
self.view.hidden = YES; // when there's no ad, let our (placeholder) view be unobstructive
adMobAd = [AdMobView requestAdWithDelegate:self]; // start a new ad request
[adMobAd retain]; // this will be released when it loads (or fails to load)
}
- (void)dealloc {
[adMobAd release];
[super dealloc];
}
#pragma mark -
#pragma mark AdMobDelegate methods
- (NSString *)publisherId {
return @"a1496226ec626d0"; // this should be prefilled; if not, get it from www.admob.com
}
- (UIColor *)adBackgroundColor {
return [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]; // this should be prefilled; if not, provide a UIColor
}
- (UIColor *)adTextColor {
return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor
}
- (BOOL)mayAskForLocation {
return YES; // this should be prefilled; if not, see AdMobProtocolDelegate.h for instructions
}
// Sent when an ad request loaded an ad; this is a good opportunity to attach
// the ad view to the hierachy.
- (void)didReceiveAd:(AdMobView *)adView {
NSLog(@"AdMob: Did receive ad");
self.view.hidden = NO;
adMobAd.frame = [self.view convertRect:self.view.frame fromView:self.view.superview]; // put the ad in the placeholder's location
[self.view addSubview:adMobAd];
autoslider = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES];
}
// Request a new ad. If a new ad is successfully loaded, it will be animated into location.
- (void)refreshAd:(NSTimer *)timer {
[adMobAd requestFreshAd];
}
// Sent when an ad request failed to load an ad
- (void)didFailToReceiveAd:(AdMobView *)adView {
NSLog(@"AdMob: Did fail to receive ad");
[adMobAd release];
adMobAd = nil;
// we could start a new ad request here, but it is unlikely that anything has changed in the last few seconds,
// so in the interests of the user's battery life, let's not
}
- (BOOL)useTestAd {
return NO;
}
@end