WLNativeAdCollectionViewCell.m 1.96 KB
//
//  WLNativeAdCollectionViewCell.m
//  DemoApp
//
//  Created by Nick Xirotyris on 19/10/15.
//  Copyright © 2015 YC. All rights reserved.
//

#import "WLNativeAdCollectionViewCell.h"
#import "Warply.h"

//#import "WLGlobals.h"

@implementation WLNativeAdCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        // Initialization code
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"WLNativeAdCollectionViewCell" owner:self options:nil];
        
        if ([arrayOfViews count] < 1) {
            return nil;
        }
        
        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
            return nil;
        }
        
        self = [arrayOfViews objectAtIndex:0];
        
    }
    
    return self;
    
}


-(void)loadContentwithURL:(NSString *)url {
    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];
}


-(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