Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Updated to AdColony SDK 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdi authored and Ferdi committed Sep 27, 2019
1 parent f1c4946 commit 4886d50
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 53 deletions.
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<framework src="StoreKit.framework"/>
<framework src="SystemConfiguration.framework"/>
<framework src="WebKit.framework"/>
<podspec>
<config>
<source url="https://github.com/AdColony/AdColony-iOS-SDK.git" />
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="AdColony" />
</pods>
</podspec>

</platform>
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest/application">
Expand Down
6 changes: 3 additions & 3 deletions src/android/adcolony.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
3 changes: 2 additions & 1 deletion src/android/com/adcolony/plugin/AdColonyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
89 changes: 49 additions & 40 deletions src/ios/AdColonyPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand All @@ -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];

}];
Expand All @@ -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"];
Expand All @@ -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) {
Expand All @@ -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]];
Expand All @@ -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];

}];
Expand Down Expand Up @@ -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 <CDVWebViewEngineProtocol> 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) {
Expand Down Expand Up @@ -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
Expand All @@ -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"];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4886d50

Please sign in to comment.