-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIADViewController.m
More file actions
177 lines (128 loc) · 4.57 KB
/
IADViewController.m
File metadata and controls
177 lines (128 loc) · 4.57 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// IADViewController.m
// DDayReminder
//
// Created by 모근원 on 12. 5. 16..
// Copyright (c) 2012년 __MyCompanyName__. All rights reserved.
//
#import "IADViewController.h"
@interface BannerViewManager : NSObject
@property (nonatomic, readonly) ADBannerView *bannerView;
+ (BannerViewManager *)sharedInstance;
@end
@implementation IADViewController
@synthesize delegate,currentIADView;
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
-(id)initWithRootViewController:(UIViewController *)_rootViewCont withCustomRootFrame:(CGRect)_cFrame;{
self = [super init];
if (self) {
NSLog(@"IAD INIT");
// Do any additional setup after loading the view.
self.currentIADView = [BannerViewManager sharedInstance].bannerView;
NSLog(@"initWithRootViewController iad ");
//위치는 광고 가져온다음 다시 조정된다. 이것은 임시 위치값.
CGRect frame = self.currentIADView.frame;
frame.origin = CGPointMake(0.0f, _cFrame.size.height - frame.size.height);
frame.origin.y -= _rootViewCont.tabBarController.tabBar.frame.size.height;
[[AppSetting sharedAppSetting] printCGRect:frame withDesc:@"IAD FRAME"];
self.currentIADView.frame = frame;
self.currentIADView.delegate = self;
// Set the autoresizing mask so that the banner is pinned to the bottom
self.currentIADView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // | UIViewAutoresizingFlexibleTopMargin;
self.currentIADView.tag = _AD_IAD + 100;
//TODO: TEST
self.currentIADView.backgroundColor = UIColorFromRGB(0xefeff4);
if (![self.currentIADView.superview isEqual:_rootViewCont.view]) {
[_rootViewCont.view addSubview:self.currentIADView];
}
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(BOOL)isADShow{
return self.currentIADView.bannerLoaded;
//return launchedAD;
}
#pragma mark -
#pragma mark iAD ADBannerViewDelegate methods
//광고 얻어오기 성공
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"iad bannerViewDidLoadAd");
launchedAD = YES;
if (delegate && [delegate respondsToSelector:@selector(iADReceiveSuccess)]){
[delegate iADReceiveSuccess];
}
}
//광고 얻어오기 실패
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"iad : %@",error.localizedDescription);
if (delegate && [delegate respondsToSelector:@selector(iADReceiveSuccess)]){
[delegate iADReceiveFail];
}
}
//광고 클릭시
-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(@"iad bannerViewActionShouldBegin");
if (delegate && [delegate respondsToSelector:@selector(iADWillOpen)]){
[delegate iADWillOpen];
}
return YES;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
NSLog(@"iad bannerViewActionDidFinish");
if (delegate && [delegate respondsToSelector:@selector(iADDidClose)]){
[delegate iADDidClose];
}
}
@end
@implementation BannerViewManager {
//ADBannerView *_bannerView; //@property 에서 선언하면 자동으로 내부 _변수 (언더바 변수)를 생성해서 @synthersize 를 걸어줌.
//NSMutableSet *_bannerViewControllers;
}
+ (BannerViewManager *)sharedInstance
{
static BannerViewManager *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[BannerViewManager alloc] init];
});
return sharedInstance;
}
- (instancetype)init
{
self = [super init];
if (self != nil) {
// On iOS 6 ADBannerView introduces a new initializer, use it when available.
if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
_bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
_bannerView = [[ADBannerView alloc] init];
}
// NSLog(@"_bannerview instance %@ from manager",_bannerView);
//_bannerView.delegate = self;
//_bannerViewControllers = [[NSMutableSet alloc] init];
}
return self;
}
@end