From 4886d505016fedc9943fbb0b8c2a97668ef83706 Mon Sep 17 00:00:00 2001 From: Ferdi Date: Fri, 27 Sep 2019 14:37:47 +0200 Subject: [PATCH] Updated to AdColony SDK 4.1 --- README.md | 39 ++++++-- plugin.xml | 10 +++ src/android/adcolony.gradle | 6 +- .../com/adcolony/plugin/AdColonyPlugin.java | 3 +- src/ios/AdColonyPlugin.m | 89 ++++++++++--------- 5 files changed, 94 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index cbe38ec..f90f626 100755 --- a/README.md +++ b/README.md @@ -3,19 +3,19 @@ AdColony ads for Apache Cordova. Allows you to integrate with AdColony from within a Cordova app, supporting both Android and iOS. Requires the AdColony SDK -iOS SDK version is 3.2.1.0 64bit production +iOS SDK version is 4.1.0 -Android SDK version is 3.2.1 +Android SDK version is 4.1.0 Please make sure that you read the AdColony Project setup guides for both Android and iOS if you're building on both platforms. All the documentation is available from here: -[AdColony Android SDK 3](https://github.com/AdColony/AdColony-Android-SDK-3) +[AdColony Android SDK](รง) -[AdColony iOS SDK 3](https://github.com/AdColony/AdColony-iOS-SDK-3) +[AdColony iOS SDK](https://github.com/AdColony/AdColony-iOS-SDK) -I recommend that you use cocoapods to install the AdColony Framework dependency +This update integrates AdColony using a podspec in the plugin definition # Install plugin @@ -43,25 +43,46 @@ APP\_ID=appbdee68ae27024084bb334a ZONE_ID=vzf8e4e97704c4445c87504e +Please note that you must follow steps 2 onwards in the AdColony Project Setup notes + # Methods #### AdColony.configureWithAppID(appID, zoneIDs, options) Initial method wich connects to AdColony. (string) appID - the appID of your app in AdColony Dashboard ([strings]) zoneIDs - array of your ad zones ids -options - app options defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/3.1.0/Classes/AdColonyAppOptions.html) +options - app options defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/4.1.0/Classes/AdColonyAppOptions.html) #### AdColony.setAppOptions(options) Set App Options. -options - JSON Array typically with ONE element a JSON object with the options. Options defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/3.1.0/Classes/AdColonyAppOptions.html) +options - JSON Array typically with ONE element a JSON object with the options. Options defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/4.1.0/Classes/AdColonyAppOptions.html) + +Note that I use the following strings from the Android SDK for cross-platform compatability + +``` +orientation +app_orientation +origin_store +disable_logging +user_id +gdpr_required +consent_string +test_mode +multi_window_enabled +mediation_network +mediation_network_version +plugin +plugin_version +keep_screen_on +``` #### AdColony.setAdOptions(options) Set Ad options. -options - JSON Array typically with ONE element a JSON object with the options. Options defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/3.1.0/Classes/AdColonyAdOptions.html) +options - JSON Array typically with ONE element a JSON object with the options. Options defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/4.1.0/Classes/AdColonyAdOptions.html) #### AdColony.setUserMetaData(metadata) Set User meta-data for ad retrieval. Calling this sets the user metadata for all future ad requests -metadata - JSON Array typically with ONE element a JSON object with the user meta-data. User meta-data defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/3.1.0/Classes/AdColonyUserMetadata.html) +metadata - JSON Array typically with ONE element a JSON object with the user meta-data. User meta-data defined [here](https://adcolony-www-common.s3.amazonaws.com/Appledoc/4.1.0/Classes/AdColonyUserMetadata.html) #### AdColony.requestInterstitialInZone(zoneID) diff --git a/plugin.xml b/plugin.xml index ee7053c..a13154c 100755 --- a/plugin.xml +++ b/plugin.xml @@ -42,6 +42,16 @@ + + + + + + + + + + diff --git a/src/android/adcolony.gradle b/src/android/adcolony.gradle index ca9a7fb..c911f72 100644 --- a/src/android/adcolony.gradle +++ b/src/android/adcolony.gradle @@ -6,7 +6,7 @@ repositories { } dependencies { - compile 'com.adcolony:sdk:3.2.1' - compile 'com.google.android.gms:play-services-ads:10.0.1' - compile 'com.android.support:support-annotations:25.0.1' + implementation 'com.adcolony:sdk:4.1.0' + implementation 'com.google.android.gms:play-services-ads:10.0.1' + implementation 'com.android.support:support-annotations:28.0.0' } diff --git a/src/android/com/adcolony/plugin/AdColonyPlugin.java b/src/android/com/adcolony/plugin/AdColonyPlugin.java index 045b6f6..95c98c6 100644 --- a/src/android/com/adcolony/plugin/AdColonyPlugin.java +++ b/src/android/com/adcolony/plugin/AdColonyPlugin.java @@ -22,7 +22,8 @@ * @author Ferdi Ladeira SmartMobiWare Ltd * */ - package com.adcolony.plugin; + +package com.adcolony.plugin; import android.content.pm.PackageManager; import android.util.Log; diff --git a/src/ios/AdColonyPlugin.m b/src/ios/AdColonyPlugin.m index b9b7749..98bbcb2 100644 --- a/src/ios/AdColonyPlugin.m +++ b/src/ios/AdColonyPlugin.m @@ -41,12 +41,12 @@ @implementation AdColonyPlugin - (void) configureWithAppID: (CDVInvokedUrlCommand*) command{ [self.commandDelegate runInBackground:^{ - rewardCallBackReady = false; - adColonyAppOptions = [AdColony getAppOptions]; - if (adColonyAppOptions == nil) - adColonyAppOptions = [[AdColonyAppOptions alloc] init]; - adColonyAdOptions = [[AdColonyAdOptions alloc] init]; - adColonyUserMetaData = [[AdColonyUserMetadata alloc] init]; + self->rewardCallBackReady = false; + self->adColonyAppOptions = [AdColony getAppOptions]; + if (self->adColonyAppOptions == nil) + self->adColonyAppOptions = [[AdColonyAppOptions alloc] init]; + self->adColonyAdOptions = [[AdColonyAdOptions alloc] init]; + self->adColonyUserMetaData = [[AdColonyUserMetadata alloc] init]; @try { [self setAppID:[command.arguments objectAtIndex:0]]; [self setZoneIDs:[NSArray arrayWithObjects:[command.arguments objectAtIndex:1], nil]]; @@ -55,8 +55,8 @@ - (void) configureWithAppID: (CDVInvokedUrlCommand*) command{ NSLog(@"Invalid configuration parameter"); } - [self configureWithAppID:_appID - andZoneIDs:_zoneIDs + [self configureWithAppID:self->_appID + andZoneIDs:self->_zoneIDs withCallBackId:command.callbackId]; }]; @@ -66,10 +66,10 @@ - (void) setAppOptions: (CDVInvokedUrlCommand*) command{ [self.commandDelegate runInBackground:^{ NSDictionary *appOptions = [command.arguments objectAtIndex:0]; - if (adColonyAppOptions == nil) - adColonyAppOptions = [AdColony getAppOptions]; - if (adColonyAppOptions == nil) - adColonyAppOptions = [[AdColonyAppOptions alloc] init]; + if (self->adColonyAppOptions == nil) + self->adColonyAppOptions = [AdColony getAppOptions]; + if (self->adColonyAppOptions == nil) + self->adColonyAppOptions = [[AdColonyAppOptions alloc] init]; [self processAppOptions:appOptions]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"SetAppOptions"]; @@ -82,19 +82,19 @@ - (void) setAdOptions: (CDVInvokedUrlCommand*) command{ [self.commandDelegate runInBackground:^{ NSDictionary *adOptions = [command.arguments objectAtIndex:0]; - if (adColonyAdOptions == nil) - adColonyAdOptions = [[AdColonyAdOptions alloc] init]; + if (self->adColonyAdOptions == nil) + self->adColonyAdOptions = [[AdColonyAdOptions alloc] init]; for (id key in adOptions) { @try { NSString *val =[adOptions objectForKey:key]; if ([key caseInsensitiveCompare:@"confirmation_enabled"] == NSOrderedSame) { - [adColonyAdOptions setShowPrePopup:[val boolValue]]; + [self->adColonyAdOptions setShowPrePopup:[val boolValue]]; continue; } if ([key caseInsensitiveCompare:@"results_enabled"] == NSOrderedSame) { - [adColonyAdOptions setShowPostPopup:[val boolValue]]; + [self->adColonyAdOptions setShowPostPopup:[val boolValue]]; continue; } } @catch (NSException *ex) { @@ -118,55 +118,55 @@ - (void) setUserMetaData: (CDVInvokedUrlCommand*) command{ [self.commandDelegate runInBackground:^{ NSDictionary *metadata = [command.arguments objectAtIndex:0]; - if (adColonyUserMetaData == nil) - adColonyUserMetaData = [[AdColonyUserMetadata alloc] init]; + if (self->adColonyUserMetaData == nil) + self->adColonyUserMetaData = [[AdColonyUserMetadata alloc] init]; for (id key in metadata) { NSString *val = [metadata objectForKey:key]; @try { if ([key caseInsensitiveCompare:@"adc_age"] == NSOrderedSame) { - [adColonyUserMetaData setUserAge:[val integerValue]]; + [self->adColonyUserMetaData setUserAge:[val integerValue]]; continue; } if ([key caseInsensitiveCompare:@"adc_gender"] == NSOrderedSame) { - [adColonyUserMetaData setUserGender:val]; + [self->adColonyUserMetaData setUserGender:val]; continue; } if ([key caseInsensitiveCompare:@"adc_marital_status"] == NSOrderedSame) { - [adColonyUserMetaData setUserMaritalStatus:val]; + [self->adColonyUserMetaData setUserMaritalStatus:val]; continue; } if ([key caseInsensitiveCompare:@"adc_education"] == NSOrderedSame) { - [adColonyUserMetaData setUserEducationLevel:val]; + [self->adColonyUserMetaData setUserEducationLevel:val]; continue; } if ([key caseInsensitiveCompare:@"adc_household_income"] == NSOrderedSame) { - [adColonyUserMetaData setUserHouseholdIncome:[NSNumber numberWithDouble:[val doubleValue]]]; + [self->adColonyUserMetaData setUserHouseholdIncome:[NSNumber numberWithDouble:[val doubleValue]]]; continue; } if ([key caseInsensitiveCompare:@"adc_zip"] == NSOrderedSame) { - [adColonyUserMetaData setUserZipCode:val]; + [self->adColonyUserMetaData setUserZipCode:val]; continue; } if ([key caseInsensitiveCompare:@"adc_interests"] == NSOrderedSame) { - [adColonyUserMetaData setUserInterests:[NSArray arrayWithObject:val]]; + [self->adColonyUserMetaData setUserInterests:[NSArray arrayWithObject:val]]; continue; } if ([key caseInsensitiveCompare:@"adc_longitude"] == NSOrderedSame) { - [adColonyUserMetaData setUserLongitude:[NSNumber numberWithDouble:[val doubleValue]]]; + [self->adColonyUserMetaData setUserLongitude:[NSNumber numberWithDouble:[val doubleValue]]]; continue; } if ([key caseInsensitiveCompare:@"adc_latitude"] == NSOrderedSame) { - [adColonyUserMetaData setUserLatitude:[NSNumber numberWithDouble:[val doubleValue]]]; + [self->adColonyUserMetaData setUserLatitude:[NSNumber numberWithDouble:[val doubleValue]]]; continue; } } @catch (NSException *ex) { NSLog(@"Invalid key/value pair :%@:%@",key,[metadata objectForKey:key]); } } - if (adColonyAdOptions == nil) - adColonyAdOptions = [[AdColonyAdOptions alloc] init]; - [adColonyAdOptions setUserMetadata:adColonyUserMetaData]; - [adColonyAppOptions setUserMetadata:adColonyUserMetaData]; + if (self->adColonyAdOptions == nil) + self->adColonyAdOptions = [[AdColonyAdOptions alloc] init]; + [self->adColonyAdOptions setUserMetadata:self->adColonyUserMetaData]; + [self->adColonyAppOptions setUserMetadata:self->adColonyUserMetaData]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"SetUserMetaData"]; [pluginResult setKeepCallback:[NSNumber numberWithInteger:0]]; @@ -185,7 +185,7 @@ - (void) requestInterstitialInZone: (CDVInvokedUrlCommand*) command{ - (void) requestInterstitial: (CDVInvokedUrlCommand*) command{ [self.commandDelegate runInBackground:^{ - [self requestInterstitialInZone:[_zoneIDs objectAtIndex:0] + [self requestInterstitialInZone:[self->_zoneIDs objectAtIndex:0] withCallbackId:command.callbackId]; }]; @@ -214,21 +214,21 @@ - (void) registerRewardReceiver:(CDVInvokedUrlCommand *)command { [self.commandDelegate runInBackground:^{ - if (_zone == nil) { - _zone = [AdColony zoneForID:[_zoneIDs firstObject]]; - if (_zone == nil) { + if (self->_zone == nil) { + self->_zone = [AdColony zoneForID:[self->_zoneIDs firstObject]]; + if (self->_zone == nil) { CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR - messageAsString:[NSString stringWithFormat:@"Invalid Zone %@",[_zoneIDs firstObject]]]; + messageAsString:[NSString stringWithFormat:@"Invalid Zone %@",[self->_zoneIDs firstObject]]]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; return; } } - NSString *zoneID = _zone.identifier; + NSString *zoneID = self->_zone.identifier; UIView *webView = self.webView; id webViewEngine = self.webViewEngine; - _zone.reward = ^(BOOL success, NSString *name, int amount) { + self->_zone.reward = ^(BOOL success, NSString *name, int amount) { // The Zone handler sends this back to the calling app if (success) { @@ -298,7 +298,7 @@ - (void) requestInterstitialInZone:(NSString *) zone withCallbackId:(NSString *) }; ad.expire = ^{ - _adColonyInterstitial = nil; + self->_adColonyInterstitial = nil; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"AdColonyRequestExpiring"]; [pluginResult setKeepCallback:[NSNumber numberWithInteger:0]]; // Should be the end of this callback @@ -309,7 +309,7 @@ - (void) requestInterstitialInZone:(NSString *) zone withCallbackId:(NSString *) } }; - _adColonyInterstitial = ad; + self->_adColonyInterstitial = ad; if (callbackId) { CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"AdColonyRequestFilled"]; @@ -362,6 +362,15 @@ - (void) processAppOptions:(NSDictionary *) appOptions { [adColonyAppOptions setUserID:val]; continue; } + if ([key caseInsensitiveCompare:@"gdpr_required"] == NSOrderedSame) { + [adColonyAppOptions setGdprRequired:val]; + continue; + } + if ([key caseInsensitiveCompare:@"consent_string"] == NSOrderedSame) { + [adColonyAppOptions setGdprConsentString:val]; + continue; + } + @try { [adColonyAppOptions setValue:val forKey:key]; } @catch (NSException *ex) {