|
| 1 | +// |
| 2 | +// inReadTopCollectionViewController.m |
| 3 | +// TeadsSDKDemo |
| 4 | +// |
| 5 | +// Created by Nikolaï Roycourt on 15/11/2016. |
| 6 | +// Copyright © 2016 Teads. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "InReadTopCollectionViewController.h" |
| 10 | +#import "CustomCollectionViewCell.h" |
| 11 | + |
| 12 | +@interface InReadTopCollectionViewController () |
| 13 | + |
| 14 | +@property (strong, nonatomic) TeadsAd *teadsAd; |
| 15 | + |
| 16 | +@end |
| 17 | + |
| 18 | +@implementation InReadTopCollectionViewController |
| 19 | + |
| 20 | +static NSString * const reuseIdentifier = @"cell"; |
| 21 | + |
| 22 | +- (void)viewDidLoad { |
| 23 | + [super viewDidLoad]; |
| 24 | + |
| 25 | + // Register cell classes |
| 26 | +// [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; |
| 27 | + |
| 28 | + self.navigationItem.title = @"inRead Top CollectionView"; |
| 29 | + |
| 30 | + NSString *pid = [[NSUserDefaults standardUserDefaults] stringForKey:@"pid"]; |
| 31 | + |
| 32 | + self.teadsAd = [[TeadsAd alloc] initInReadTopWithPlacementId:pid scrollView:self.collectionView delegate:self]; |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +#pragma mark UICollectionViewDelegateFlowLayout |
| 37 | + |
| 38 | +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath |
| 39 | +{ |
| 40 | + return CGSizeMake(([UIScreen mainScreen].bounds.size.width-30)/2 , 200); |
| 41 | +} |
| 42 | + |
| 43 | +- (void)didReceiveMemoryWarning { |
| 44 | + [super didReceiveMemoryWarning]; |
| 45 | + // Dispose of any resources that can be recreated. |
| 46 | +} |
| 47 | + |
| 48 | +-(void)viewDidAppear:(BOOL)animated { |
| 49 | + [super viewDidAppear:animated]; |
| 50 | + |
| 51 | + if (self.teadsAd.isLoaded) { |
| 52 | + [self.teadsAd viewControllerAppeared:self]; |
| 53 | + |
| 54 | + } else { |
| 55 | + [self.teadsAd load]; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +-(void)viewDidDisappear:(BOOL)animated { |
| 60 | + [super viewDidDisappear:animated]; |
| 61 | + |
| 62 | + [self.teadsAd viewControllerDisappeared:self]; |
| 63 | +} |
| 64 | + |
| 65 | +#pragma mark <UICollectionViewDataSource> |
| 66 | + |
| 67 | +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { |
| 68 | + return 1; |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { |
| 73 | + return 20; |
| 74 | +} |
| 75 | + |
| 76 | +- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { |
| 77 | + CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; |
| 78 | + |
| 79 | + cell.titleLabel.text = [NSString stringWithFormat:@"section %ld - row %ld", (long)indexPath.section, (long)indexPath.row]; |
| 80 | + |
| 81 | + return cell; |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +#pragma mark - |
| 86 | +#pragma mark - TeadsAdDelegate |
| 87 | + |
| 88 | +/** |
| 89 | + * NativeVideo Failed to Load |
| 90 | + * |
| 91 | + * @param interstitial : the TeadsAd object |
| 92 | + * @param error : the TeadsError object |
| 93 | + */ |
| 94 | +- (void)teadsAd:(TeadsAd *)nativeVideo didFailLoading:(TeadsError *)error { |
| 95 | + |
| 96 | +} |
| 97 | + |
| 98 | +/** |
| 99 | + * NativeVideo Will Load (loading) |
| 100 | + * |
| 101 | + * @param interstitial : the TeadsAd object |
| 102 | + */ |
| 103 | +- (void)teadsAdWillLoad:(TeadsAd *)nativeVideo { |
| 104 | + |
| 105 | +} |
| 106 | + |
| 107 | +/** |
| 108 | + * NativeVideo Did Load (loaded successfully) |
| 109 | + * |
| 110 | + * @param interstitial : the TeadsAd object |
| 111 | + */ |
| 112 | +- (void)teadsAdDidLoad:(TeadsAd *)nativeVideo { |
| 113 | + |
| 114 | +} |
| 115 | + |
| 116 | +/** |
| 117 | + * NativeVideo Will Start Playing (loading) |
| 118 | + * |
| 119 | + * @param nativeVideo : the TeadsAd object |
| 120 | + */ |
| 121 | +- (void)teadsAdWillStart:(TeadsAd *)nativeVideo { |
| 122 | + |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * NativeVideo Did Start Playing (playing) |
| 127 | + * |
| 128 | + * @param nativeVideo : the TeadsAd object |
| 129 | + */ |
| 130 | +- (void)teadsAdDidStart:(TeadsAd *)nativeVideo { |
| 131 | + |
| 132 | +} |
| 133 | + |
| 134 | +/** |
| 135 | + * NativeVideo Will Stop Playing (stopping) |
| 136 | + * |
| 137 | + * @param nativeVideo : the TeadsAd object |
| 138 | + */ |
| 139 | +- (void)teadsAdWillStop:(TeadsAd *)nativeVideo { |
| 140 | + |
| 141 | +} |
| 142 | + |
| 143 | +/** |
| 144 | + * NativeVideo Did Stop Playing (stopped) |
| 145 | + * |
| 146 | + * @param nativeVideo : the TeadsAd object |
| 147 | + */ |
| 148 | +- (void)teadsAdDidStop:(TeadsAd *)nativeVideo { |
| 149 | + |
| 150 | +} |
| 151 | + |
| 152 | +/** |
| 153 | + * NativeVideo Did Pause (paused) |
| 154 | + * |
| 155 | + * @param nativeVideo : the TeadsAd object |
| 156 | + */ |
| 157 | +- (void)teadsAdDidPause:(TeadsAd *)nativeVideo { |
| 158 | + |
| 159 | +} |
| 160 | + |
| 161 | +/** |
| 162 | + * NativeVideo Did Resume (playing) |
| 163 | + * |
| 164 | + * @param nativeVideo : the TeadsAd object |
| 165 | + */ |
| 166 | +- (void)teadsAdDidResume:(TeadsAd *)nativeVideo { |
| 167 | + |
| 168 | +} |
| 169 | + |
| 170 | +/** |
| 171 | + * NativeVideo Did Mute Sound |
| 172 | + * |
| 173 | + * @param nativeVideo : the TeadsAd object |
| 174 | + */ |
| 175 | +- (void)teadsAdDidMute:(TeadsAd *)nativeVideo { |
| 176 | + |
| 177 | +} |
| 178 | + |
| 179 | +/** |
| 180 | + * NativeVideo Did Unmute Sound |
| 181 | + * |
| 182 | + * @param nativeVideo : the TeadsAd object |
| 183 | + */ |
| 184 | +- (void)teadsAdDidUnmute:(TeadsAd *)nativeVideo { |
| 185 | + |
| 186 | +} |
| 187 | + |
| 188 | +/** |
| 189 | + * NativeVideo Will expand |
| 190 | + * |
| 191 | + * @param nativeVideo : the TeadsAd object |
| 192 | + */ |
| 193 | +- (void)teadsAdDidExpand:(TeadsAd *)video { |
| 194 | + |
| 195 | +} |
| 196 | + |
| 197 | +/** |
| 198 | + * NativeVideo Will collapse |
| 199 | + * |
| 200 | + * @param nativeVideo : the TeadsAd object |
| 201 | + */ |
| 202 | +- (void)teadsAdWillCollapse:(TeadsAd *)video { |
| 203 | + |
| 204 | +} |
| 205 | + |
| 206 | +/** |
| 207 | + * NativeVideo did collapse |
| 208 | + * |
| 209 | + * @param nativeVideo : the TeadsAd object |
| 210 | + */ |
| 211 | +- (void)teadsAdDidCollapse:(TeadsAd *)video { |
| 212 | + |
| 213 | +} |
| 214 | + |
| 215 | +/** |
| 216 | + * NativeVideo was clicked |
| 217 | + * |
| 218 | + * @param nativeVideo : the TeadsAd object |
| 219 | + */ |
| 220 | +- (void)teadsAdWasClicked:(TeadsAd *)nativeVideo { |
| 221 | + |
| 222 | +} |
| 223 | + |
| 224 | +/** |
| 225 | + * NativeVideo Did Stop Playing (stopped) |
| 226 | + * |
| 227 | + * @param nativeVideo : the TeadsAd object |
| 228 | + */ |
| 229 | +- (void)teadsAdDidClickBrowserClose:(TeadsAd *)nativeVideo { |
| 230 | + |
| 231 | +} |
| 232 | + |
| 233 | +/** |
| 234 | + * NativeVideo Will Take Over Fullscreen |
| 235 | + * |
| 236 | + * @param nativeVideo : the TeadsAd object |
| 237 | + */ |
| 238 | +- (void)teadsAdWillTakeOverFullScreen:(TeadsAd *)nativeVideo { |
| 239 | + |
| 240 | +} |
| 241 | + |
| 242 | +/** |
| 243 | + * NativeVideo Did Take Over Fullscreen |
| 244 | + * |
| 245 | + * @param nativeVideo : the TeadsAd object |
| 246 | + */ |
| 247 | +- (void)teadsAdDidTakeOverFullScreen:(TeadsAd *)nativeVideo { |
| 248 | + |
| 249 | +} |
| 250 | + |
| 251 | +/** |
| 252 | + * NativeVideo Will Dismiss Fullscreen |
| 253 | + * |
| 254 | + * @param nativeVideo : the TeadsAd object |
| 255 | + */ |
| 256 | +- (void)teadsAdWillDismissFullscreen:(TeadsAd *)nativeVideo { |
| 257 | + |
| 258 | +} |
| 259 | + |
| 260 | +/** |
| 261 | + * NativeVideo Did Dismiss Fullscreen |
| 262 | + * |
| 263 | + * @param nativeVideo : the TeadsAd object |
| 264 | + */ |
| 265 | +- (void)teadsAdDidDismissFullscreen:(TeadsAd *)nativeVideo { |
| 266 | + |
| 267 | +} |
| 268 | + |
| 269 | +/** |
| 270 | + * NativeVideo Skip Button Was Tapped (skip button pressed) |
| 271 | + * |
| 272 | + * @param nativeVideo : the TeadsAd object |
| 273 | + */ |
| 274 | +- (void)teadsAdSkipButtonTapped:(TeadsAd *)nativeVideo { |
| 275 | + |
| 276 | +} |
| 277 | + |
| 278 | +/** |
| 279 | + * NativeVideo Skip Button Did Show (skip button appeared) |
| 280 | + * |
| 281 | + * @param nativeVideo : the TeadsAd object |
| 282 | + */ |
| 283 | +- (void)teadsAdSkipButtonDidShow:(TeadsAd *)nativeVideo { |
| 284 | + |
| 285 | +} |
| 286 | + |
| 287 | +/** |
| 288 | + * NativeVideo did clean (all related resoures have been removed) |
| 289 | + * |
| 290 | + * @param nativeVideo : the TeadsAd object |
| 291 | + */ |
| 292 | +- (void)teadsAdDidClean:(TeadsAd *)nativeVideo { |
| 293 | + |
| 294 | +} |
| 295 | + |
| 296 | +@end |
0 commit comments