-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeAdViewController.m
More file actions
200 lines (149 loc) · 6.5 KB
/
Copy pathNativeAdViewController.m
File metadata and controls
200 lines (149 loc) · 6.5 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
// NativeAdViewController.m
// DemoApp
//
// Created by Ofir Kariv 1/1/19
// Copyright © 2019 MobFox Ltd. All rights reserved.
//
#import "NativeAdViewController.h"
#import "NativeAdCell.h"
@interface NativeAdViewController ()
@property (strong, nonatomic) MobFoxNativeAd* nativeAd;
@property (nonatomic, strong) IBOutlet UIView* topBlock;
@property (nonatomic, strong) IBOutlet UIView* midBlock;
@property (nonatomic, strong) IBOutlet UIView* bottomBlock;
@end
@implementation NativeAdViewController
{
NSString *demo_hash;
}
- (void)styleAdjustments {
self.loadTextField.borderStyle = UITextBorderStyleNone;
self.loadTextField.textAlignment = NSTextAlignmentCenter;
self.loadTextField.layer.cornerRadius = 20;
self.loadTextField.layer.borderWidth = 2;
self.loadTextField.layer.masksToBounds = true;
self.loadTextField.layer.borderColor = [UIColor grayColor].CGColor;
self.loadTextField.font = [UIFont fontWithName:@"Helvetica" size:12];
self.loadButtonProperty.layer.borderWidth = 2.0;
self.loadButtonProperty.layer.borderColor = [UIColor grayColor].CGColor;
self.loadButtonProperty.layer.cornerRadius = 20;
self.scanButtonProperty.layer.borderWidth = 2.0;
self.scanButtonProperty.layer.borderColor = [UIColor darkGrayColor].CGColor;
self.scanButtonProperty.layer.cornerRadius = 20;
}
- (void)InsetsAdjustments
{
CGFloat topInset = 20.0;
CGFloat bottomInset = 0.0;
if (@available(iOS 11.0, *)) {
topInset = [UIApplication sharedApplication].keyWindow.safeAreaInsets.top;
bottomInset = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
if (topInset==0) topInset=20;
}
CGRect rcTop = _topBlock.frame;
CGRect rcMid = _midBlock.frame;
CGRect rcBottm = _bottomBlock.frame;
_topBlock.frame = CGRectMake(rcTop.origin.x, rcTop.origin.y+topInset,
rcTop.size.width, rcTop.size.height);
_bottomBlock.frame = CGRectMake(rcBottm.origin.x, rcBottm.origin.y-bottomInset,
rcBottm.size.width, rcBottm.size.height);
CGFloat midYTop = _topBlock.frame.origin.y + _topBlock.frame.size.height;
CGFloat midYBottom = _bottomBlock.frame.origin.y-1;
_midBlock.frame = CGRectMake(rcMid.origin.x, midYTop,
rcMid.size.width, midYBottom-midYTop);
}
- (void)viewDidLoad {
[super viewDidLoad];
demo_hash = @"a764347547748896b84e0b8ccd90fd62";
self.nativeAd = [[MobFoxNativeAd alloc] init:demo_hash nativeView:_nativeView];
_nativeAd.delegate = self;
self.loadTextField.rightViewMode = UITextFieldViewModeAlways;
if(self.invh.length == 0)
[self setInvh:demo_hash];
self.loadTextField.text = self.invh;
self.loadTextField.placeholder = self.invh;
self.loadTextField.delegate = self;
[self InsetsAdjustments];
[self styleAdjustments];
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)]];
}
- (void)viewDidAppear:(BOOL)animated{
_loadTextField.text = demo_hash;
}
-(void)dismissKeyboard {
[self.loadTextField resignFirstResponder];
}
- (void)updateHashAfterScan:(NSString *)hash{
[self setInvh:hash];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"nativeToScan"]){
ScanHashViewController *vc = [segue destinationViewController];
vc.vcType = [segue identifier];
vc.delegate = self;
}
}
- (IBAction)onScan:(id)sender {
[self performSegueWithIdentifier:@"nativeToScan" sender:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)loadNativeAd:(id)sender {
// Start activity indicator
[[ProgressView shared] startAnimation:self.view];
[_nativeAd loadAd];
}
//called when ad response is returned
- (void)MobFoxNativeAdDidLoad:(MobFoxNativeAd*)ad withAdData:(MobFoxNativeData *)adData{
[[ProgressView shared] stopAnimation];
_nativeIcon.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:adData.icon.url]];
_nativeMainImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:adData.main.url]];
_nativeHeadline.text = adData.assetHeadline;
_nativeDesc.text = adData.assetDescription;
}
//called when ad response cannot be returned
- (void)MobFoxNativeAdDidFailToReceiveAdWithError:(NSError *)error{
// Stop activity indicator
[[ProgressView shared] stopAnimation];
NSLog(@"%@", [error description]);
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Load Fail"
message:[error description]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
//move buttons in for keyboard
self.view.frame = CGRectMake(self.view.frame.origin.x,
(self.view.frame.origin.y)-((self.view.frame.size.height)*0.333),
self.view.frame.size.width,
self.view.frame.size.height);
if([textField isEqual:self.loadTextField]){
}
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
//move buttons after keyboard disappears
self.view.frame = CGRectMake(self.view.frame.origin.x,
(self.view.frame.origin.y)+((self.view.frame.size.height)*0.333),
self.view.frame.size.width,
self.view.frame.size.height);
}
//called on ad click
- (void)MobFoxNativeAdClicked{
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end