WLNativeAdTableViewCell.m
2.87 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
//
// WLNativeAdTableViewCell.m
// DemoApp
//
// Created by Nick Xirotyris on 14/10/15.
// Copyright © 2015 YC. All rights reserved.
//
#import "WLNativeAdTableViewCell.h"
#import "Warply.h"
#import <WebKit/WebKit.h>
#import "UIImageView+AFNetworking.h"
//#import "WLGlobals.h"
@implementation WLNativeAdTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.webView.UIDelegate = self;
self.adImageView.clipsToBounds = YES;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)setupCellWithItem:(WLInboxItem *)item {
self.item = item;
self.adLabel.text = item.title;
self.webView.alpha = 0;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[item getImageURL]]];
[self.activityIndicator startAnimating];
[self.adImageView setImageWithURLRequest:request
placeholderImage:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[self.activityIndicator stopAnimating];
self.adImageView.image = image;
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
[self.activityIndicator stopAnimating];
}];
}
-(void)loadContentwithURL:(NSString *)url {
self.adLabel.alpha = 0;
self.adImageView.alpha = 0;
NSMutableURLRequest * request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
[request setValue:[Warply sharedService].webId forHTTPHeaderField:@"loyalty-web-id"];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[request setValue:@"gzip" forHTTPHeaderField:@"User-Agent"];
[self.webView loadRequest:request];
[self.activityIndicator startAnimating];
}
#pragma mark - WebView Delegate
-(BOOL)webView:(WKWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (![request.URL.host isEqualToString:WARP_HOST] && ![request.URL.host isEqualToString:@"warplydata.blob.core.windows.net"]) {
[[UIApplication sharedApplication] openURL:request.URL];
}
return YES;
}
-(void)webViewDidFinishLoad:(WKWebView *)webView {
[self.activityIndicator stopAnimating];
}
-(void)webView:(WKWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"%@", error);
[self.activityIndicator stopAnimating];
}
@end