/
AdsVungle.m
155 lines (131 loc) · 4.46 KB
/
AdsVungle.m
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
//
// AdsAdcolony.m
// Ads
//
// Created by Arturs Sosins on 6/25/13.
// Copyright (c) 2013 Gideros Mobile. All rights reserved.
//
#include "gideros.h"
#import "AdsVungle.h"
#import "AdsClass.h"
@implementation AdsVungle
-(id)init{
self.mngr = [[AdsManager alloc] init];
return self;
}
-(void)destroy{
[self.mngr destroy];
self.mngr = nil;
[[VungleSDK sharedSDK] setDelegate:nil];
}
-(void)setKey:(NSMutableArray*)parameters{
VungleSDK *sdk = [VungleSDK sharedSDK];
NSString *user = @"Player";
if([parameters count] > 1)
user = [parameters objectAtIndex:1];
NSArray *placements=NULL;
if([parameters count] > 2) {
NSRange placementsRange;
placementsRange.location = 2;
placementsRange.length = [parameters count] -2;
placements=[parameters subarrayWithRange:placementsRange];
}
else
{
placements=@[ @"Default" ];
}
self.user=user;
NSError *error=NULL;
[sdk setDelegate:self];
[sdk startWithAppId:[parameters objectAtIndex:0] placements:placements error:&error];
if (error) {
NSLog(@"Error encountered initializing vungle: %@", error);
[AdsClass adFailed:[self class] with:error.description forType:@""];
}
}
#pragma mark - VungleSDK Delegate
- (void)vungleSDKDidInitialize
{
[AdsClass adsReady:[self class] state:TRUE];
}
- (void)vungleAdPlayabilityUpdate:(BOOL)isAdPlayable placementID:(NSString *)placementID {
if (isAdPlayable) {
NSLog(@"An ad is available for playback");
[self.mngr load:placementID];
[AdsClass adReceived:[self class] forType:placementID];
} else {
NSLog(@"No ads currently available for playback");
}
}
- (void)vungleWillShowAdForPlacementID:(nullable NSString *)placementID
{
NSLog(@"An ad is about to be played!");
[AdsClass adDisplayed:[self class] forType:placementID];
}
- (void)vungleWillCloseAdWithViewInfo:(VungleViewInfo *)info placementID:(NSString *)placementID
{
if([info.completedView boolValue]){
[AdsClass adActionEnd:[self class] forType:placementID];
} else {
[AdsClass adDismissed:[self class] forType:placementID];
}
}
#pragma mark - FirstView Methods
-(IBAction)showAd: (NSString *)placement forUser:(NSString *)user {
// Grab instance of Vungle SDK
VungleSDK* sdk = [VungleSDK sharedSDK];
// Dict to set custom ad options
NSDictionary* options = @{VunglePlayAdOptionKeyUser: user,
VunglePlayAdOptionKeyIncentivizedAlertBodyText : @"If the video isn't completed you won't get your reward! Are you sure you want to close early?",
VunglePlayAdOptionKeyIncentivizedAlertCloseButtonText : @"Close",
VunglePlayAdOptionKeyIncentivizedAlertContinueButtonText : @"Keep Watching",
VunglePlayAdOptionKeyIncentivizedAlertTitleText : @"Careful!"};
// Pass in dict of options, play ad
NSError *error=NULL;
[sdk playAd:[AdsClass getRootViewController] options:options placementID:placement error:&error];
if (error) {
NSLog(@"Error encountered playing ad: %@", error);
[AdsClass adFailed:[self class] with:error.description forType:placement];
}
}
-(void)loadAd:(NSMutableArray*)parameters{
NSString *type = [parameters objectAtIndex:0];
NSString *user = self.user;
if([parameters count] > 1)
{
user = [parameters objectAtIndex:1];
}
AdsStateChangeListener *listener = [[AdsStateChangeListener alloc] init];
[listener setShow:^(){
[self showAd:type forUser:user];
}];
[listener setDestroy:^(){}];
[listener setHide:^(){}];
[self.mngr set:type forType:type withListener:listener];
NSError* error=NULL;
VungleSDK* sdk = [VungleSDK sharedSDK];
[sdk loadPlacementWithID:type error:&error];
if (error) {
NSLog(@"Error encountered loading ad: %@", error);
[AdsClass adFailed:[self class] with:error.description forType:type];
}
}
-(void)showAd:(NSMutableArray*)parameters{
NSString *type = [parameters objectAtIndex:0];
if([self.mngr get:type] == nil)
[self loadAd:parameters];
[self.mngr show:type];
}
-(void)hideAd:(NSString*)type{
[self.mngr hide:type];
}
-(void)enableTesting{
}
-(BOOL)checkConsent:(BOOL) reset forUnderAge:(BOOL) underAge
{
return FALSE;
}
-(UIView*)getView{
return nil;
}
@end