Commit a43ee9b9 authored by Jonathan Cichon's avatar Jonathan Cichon

pod update and Customer Ad Examples

parent 40a8e46b
......@@ -2,10 +2,10 @@ PODS:
- SDWebImage (4.3.3):
- SDWebImage/Core (= 4.3.3)
- SDWebImage/Core (4.3.3)
- Tickaroo2CoreEmbed (3.0.20):
- Tickaroo2CoreEmbed (3.0.21):
- SDWebImage (~> 4.0)
- TickarooBase (= 3.0.20)
- TickarooBase (3.0.20)
- TickarooBase (= 3.0.21)
- TickarooBase (3.0.21)
DEPENDENCIES:
- Tickaroo2CoreEmbed
......@@ -19,8 +19,8 @@ SPEC REPOS:
SPEC CHECKSUMS:
SDWebImage: de4d90b5bff3571eae7bd16202b1f43135409fa5
Tickaroo2CoreEmbed: 694076dae0d6d8c3049d703185665922bb0fdf82
TickarooBase: 85f2f98dbf288e9f25767d87f9ed428f56f846d8
Tickaroo2CoreEmbed: 4d7c0f50dcd3ef0890736576b2bd226e38907aa1
TickarooBase: e3ea326254c5303df81de958bf9e0ded7ed314f7
PODFILE CHECKSUM: 5d924e086c68ffe53ad7b87645dc899423482e52
......
......@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
1B572671BF39F7FC2BC4E93C /* libPods-TickarooEmbedSDKDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7897F604596167BCB8577DCB /* libPods-TickarooEmbedSDKDemo.a */; };
DB512CEC20A1909A009C46BD /* CustomerAdProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = DB512CEB20A1909A009C46BD /* CustomerAdProvider.m */; };
DB8AC7381E93E3B60095CC9F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DB8AC7371E93E3B60095CC9F /* main.m */; };
DB8AC73B1E93E3B60095CC9F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DB8AC73A1E93E3B60095CC9F /* AppDelegate.m */; };
DB8AC73E1E93E3B60095CC9F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DB8AC73D1E93E3B60095CC9F /* ViewController.m */; };
......@@ -18,6 +19,8 @@
/* Begin PBXFileReference section */
21DBCDB1C953881346B2C22B /* Pods-TickarooEmbedSDKDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TickarooEmbedSDKDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TickarooEmbedSDKDemo/Pods-TickarooEmbedSDKDemo.debug.xcconfig"; sourceTree = "<group>"; };
7897F604596167BCB8577DCB /* libPods-TickarooEmbedSDKDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-TickarooEmbedSDKDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
DB512CEA20A1909A009C46BD /* CustomerAdProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomerAdProvider.h; sourceTree = "<group>"; };
DB512CEB20A1909A009C46BD /* CustomerAdProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomerAdProvider.m; sourceTree = "<group>"; };
DB8AC7331E93E3B60095CC9F /* TickarooEmbedSDKDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TickarooEmbedSDKDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
DB8AC7371E93E3B60095CC9F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
DB8AC7391E93E3B60095CC9F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
......@@ -84,6 +87,8 @@
DB8AC73A1E93E3B60095CC9F /* AppDelegate.m */,
DB8AC73C1E93E3B60095CC9F /* ViewController.h */,
DB8AC73D1E93E3B60095CC9F /* ViewController.m */,
DB512CEA20A1909A009C46BD /* CustomerAdProvider.h */,
DB512CEB20A1909A009C46BD /* CustomerAdProvider.m */,
DB8AC7421E93E3B60095CC9F /* Assets.xcassets */,
DB8AC7441E93E3B70095CC9F /* LaunchScreen.storyboard */,
DB8AC7471E93E3B70095CC9F /* Info.plist */,
......@@ -217,6 +222,7 @@
buildActionMask = 2147483647;
files = (
DB8AC73E1E93E3B60095CC9F /* ViewController.m in Sources */,
DB512CEC20A1909A009C46BD /* CustomerAdProvider.m in Sources */,
DB8AC73B1E93E3B60095CC9F /* AppDelegate.m in Sources */,
DB8AC7381E93E3B60095CC9F /* main.m in Sources */,
);
......
......@@ -10,6 +10,8 @@
#import <Tickaroo2CoreEmbed/T2EmbedManager.h>
#import <Tickaroo2CoreEmbed/TApiUrlRef.h>
#import <Tickaroo2CoreEmbed/TApiEvent.h>
#import <Tickaroo2CoreEmbed/TApiEventRow.h>
#import <Tickaroo2CoreEmbed/TApiMilestoneRow.h>
#import "ViewController.h"
......@@ -47,7 +49,8 @@
T2EmbedOptionApiHost : @"www.tickaroo.com",
T2EmbedOptionLanguage : @"de",
T2EmbedOptionAlternativeIconLayout : @(YES),
T2EmbedOptionDisplayScoreboardNavExtension : @(false)
T2EmbedOptionDisplayScoreboardNavExtension : @(false),
T2EmbedOptionDisplayShareInSlideshow : @(false),
}
styling:@{
T2EmbedStylingBackgroundCornerRadius : @(0),
......@@ -77,6 +80,12 @@
}
}];
[[T2EmbedApperance appearance] setBottomSpacerInsets:UIEdgeInsetsMake(15, 0, 15, 0) forRow:[TApiMilestoneRow tikModelClass]];
[[T2EmbedApperance appearance] setBottomLineHeight:1 forRow:[TApiMilestoneRow tikModelClass]];
[[T2EmbedApperance appearance] setBottomSpacerInsets:UIEdgeInsetsMake(15, 0, 15, 0) forRow:[TApiEventRow tikModelClass]];
[[T2EmbedApperance appearance] setBottomLineHeight:1 forRow:[TApiEventRow tikModelClass]];
return YES;
}
......
//
// CustomerAdProvider.h
// TickarooEmbedSDKDemo
//
// Created by Jonathan Cichon on 08.05.18.
// Copyright © 2018 Tickaroo GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Tickaroo2CoreEmbed/T2EmbedManager.h>
@interface CustomerAdProvider : NSObject <T2AdProvider>
@end
//
// CustomerAdProvider.m
// TickarooEmbedSDKDemo
//
// Created by Jonathan Cichon on 08.05.18.
// Copyright © 2018 Tickaroo GmbH. All rights reserved.
//
#import <WebKit/WebKit.h>
#import <Tickaroo2CoreEmbed/TApiCustomerFrameworkAd.h>
#import <Tickaroo2CoreEmbed/TApiAdRow.h>
#import <objc/runtime.h>
#import "CustomerAdProvider.h"
@interface MyAdView : UIView <T2AdView>
@property (nonatomic, copy) void (^loadCompletionCallback)(UIView<T2AdView> *);
- (instancetype)initWithAd:(TApiCustomerFrameworkAd *)ad;
- (void)load;
@end
@interface ImageAdView : MyAdView
@property (nonatomic) UIImageView *imageView;
@end
@interface HTMLAdView : MyAdView <WKNavigationDelegate>
@property (nonatomic) WKWebView *webView;
@property (nonatomic) CGSize webContentSize;
@end
/*
add category to the adPlacement to avoid a lookup-dictionary or something for synchronization
*/
@interface TApiCustomerFrameworkAd (myCategory)
@property (nonatomic, strong) MyAdView *adView;
@end
@implementation TApiCustomerFrameworkAd (myCategory)
static void * kTApiCustomerFrameworkAd_AssociatedObject;
- (void)setAdView:(MyAdView *)adView {
objc_setAssociatedObject(self, &kTApiCustomerFrameworkAd_AssociatedObject, adView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (MyAdView *)adView {
return objc_getAssociatedObject(self, &kTApiCustomerFrameworkAd_AssociatedObject);
}
@end
/*
The Provider Interface to reuse the same view during scrolling
*/
@implementation CustomerAdProvider
+ (void)load {
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
if (version.majorVersion >= 9) {
[T2EmbedManager registerProvider:CustomerAdProvider.new forAdType:[TApiCustomerFrameworkAd class]];
}
}
- (void)loadAdViewForRow:(TApiAdRow *)row ad:(TApiAbstractAd *)ad completion:(void (^)(UIView<T2AdView> *))completion {
TApiCustomerFrameworkAd *myAd = nil;
if ([ad isKindOfClass:[TApiCustomerFrameworkAd class]]) {
myAd = (TApiCustomerFrameworkAd *)ad;
}
if (myAd) {
@synchronized (myAd) {
if (myAd.adView && myAd.adView.isLoaded) {
completion(myAd.adView);
} else {
// HTMLAdView *adView = [[HTMLAdView alloc] initWithAd:myAd];
ImageAdView *adView = [[ImageAdView alloc] initWithAd:myAd];
myAd.adView = adView;
adView.loadCompletionCallback = completion;
[adView load];
}
}
} else {
completion(nil);
}
}
@end
@implementation MyAdView
@synthesize didChangeHeight=_didChangeHeight;
@synthesize loaded=_loaded;
@synthesize ad=_ad;
- (instancetype)initWithAd:(TApiCustomerFrameworkAd *)ad {
self = [super initWithFrame:CGRectMake(0, 0, 0, 50)];
if (self) {
self.ad = ad;
[self buildUI];
}
return self;
}
- (void)willAppearOnScreen {
}
- (void)buildUI {
self.clipsToBounds = YES;
}
- (CGFloat)heightForWidth:(CGFloat)width {
return 0;
}
- (void)load {
}
@end
/*
Example for displaying HTML-Ads
*/
@implementation HTMLAdView
- (void)buildUI {
[super buildUI];
_webContentSize = CGSizeZero;
_webView = [[WKWebView alloc] initWithFrame:self.bounds];
_webView.navigationDelegate = self;
_webView.scrollView.scrollEnabled = NO;
_webView.scrollView.bounces = NO;
[self addSubview:_webView];
[_webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(UIScrollView *)scrollView change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"contentSize"]) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!CGSizeEqualToSize(scrollView.contentSize, self.webContentSize) && scrollView.contentSize.height >= 50) {
self.loaded = YES;
if (self.loadCompletionCallback) {
self.loadCompletionCallback(self);
self.loadCompletionCallback = nil;
}
self.webContentSize = scrollView.contentSize;
if (self.webContentSize.height > 0 && self.webContentSize.width > 0 && self.webContentSize.height <= 121) {
if (self.didChangeHeight) {
self.didChangeHeight();
}
}
} else if (self.loadCompletionCallback) {
self.loaded = NO;
self.loadCompletionCallback(nil);
self.loadCompletionCallback = nil;
}
});
}
}
- (void)layoutSubviews {
[super layoutSubviews];
BOOL reload = false;
if (self.webView.frame.size.width != self.frame.size.width) {
reload = YES;
}
if (!reload) {
self.webView.frame = (CGRect) {
.size = self.frame.size
};
[UIView performWithoutAnimation:^{
self.webView.alpha = 1;
}];
} else {
[UIView performWithoutAnimation:^{
self.webView.alpha = 0;
}];
self.webView.frame = (CGRect) {
.size = CGSizeMake(self.frame.size.width, 1)
};
[self reloadContent];
}
}
- (void)load {
[self reloadContent];
}
- (NSString *)googleAdBodyHTML {
return @"<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>\n<ins class=\"adsbygoogle\"\nstyle=\"display:block\"\ndata-ad-client=\"ca-pub-2908701318959838\"\ndata-ad-slot=\"7738672508\"\ndata-ad-format=\"horizontal\"></ins>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n</script>";
}
- (void)reloadContent {
[self.webView loadHTMLString:[NSString stringWithFormat:@"<html style=\"padding:0; margin:0;\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><body style=\"padding:0; margin:0;\">%@</body></html>", self.googleAdBodyHTML] baseURL:[NSURL URLWithString:@"https://www.tickaroo.com/"]];
}
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
NSLog(@"%@", error);
}
- (void)webView:(WKWebView *)webView didFailLoadWithError:(nonnull NSError *)error {
NSLog(@"%@", error);
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
[[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:nil];
decisionHandler(WKNavigationActionPolicyCancel);
} else {
decisionHandler(WKNavigationActionPolicyAllow);
}
}
- (CGFloat)heightForWidth:(CGFloat)width {
return width * self.ratio;
}
- (CGFloat)ratio {
if (_webContentSize.height > 0 && _webContentSize.width > 0 && _webContentSize.height <= 121) {
return _webContentSize.height/_webContentSize.width;
}
return 0;
}
- (void)dealloc {
[_webView.scrollView removeObserver:self forKeyPath:@"contentSize"];
}
@end
/*
Example for displaying Image-Ads
*/
@implementation ImageAdView
- (void)buildUI {
_imageView = [[UIImageView alloc] initWithFrame:self.bounds];
_imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:_imageView];
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adSelected)]];
}
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = (CGRect) {
.size = self.frame.size
};
}
- (CGFloat)heightForWidth:(CGFloat)width {
if (self.imageView.image.size.width) {
return (self.imageView.image.size.height/self.imageView.image.size.width)*width;
}
return 0;
}
- (void)load {
__weak ImageAdView *weakSelf = self;
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"https://dunhamweb.com/media/banner-sample.png"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
ImageAdView *strongSelf = weakSelf;
if (strongSelf) {
if (!error && data) {
strongSelf.imageView.image = [UIImage imageWithData:data];
strongSelf.loaded = YES;
if (strongSelf.loadCompletionCallback) {
strongSelf.loadCompletionCallback(strongSelf);
strongSelf.loadCompletionCallback = nil;
}
if (strongSelf.didChangeHeight) {
strongSelf.didChangeHeight();
}
} else {
strongSelf.loaded = FALSE;
if (strongSelf.loadCompletionCallback) {
strongSelf.loadCompletionCallback(nil);
strongSelf.loadCompletionCallback = nil;
}
}
}
});
}];
[task resume];
}
- (void)adSelected {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.de"] options:@{} completionHandler:nil];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment