Skip to content

Commit

Permalink
wip apple AppLovin
Browse files Browse the repository at this point in the history
fix apple build
  • Loading branch information
irov committed Jan 5, 2024
1 parent db525c4 commit 2d055aa
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#import "Environment/iOS/UIPluginApplicationDelegateInterface.h"

#import <AppLovinSDK/AppLovinSDK.h>

@interface AppleAppLovinApplicationDelegate : NSObject<UIPluginApplicationDelegateInterface>

+ (ALSdk * _Nonnull) AppLovinSdk;
+ (void) setAppLovinSdk:(ALSdk * _Nonnull) value;

@end


64 changes: 51 additions & 13 deletions src/Plugins/AppleAppLovinPlugin/AppleAppLovinApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@

#include "Environment/Apple/AppleDetail.h"

#import <Foundation/Foundation.h>
#import <AppLovinSDK/AppLovinSDK.h>

@implementation AppleAppLovinApplicationDelegate

static ALSdk * AppLovinSdk;

#define PLUGIN_BUNDLE_NAME @"MengineAppleAppLovinPlugin"

+ (ALSdk * _Nonnull) AppLovinSdk {
return AppLovinSdk;
}

+ (void) setAppLovinSdk:(ALSdk * _Nonnull) value {
AppLovinSdk = value;
}

#pragma mark - UIPluginApplicationDelegateInterface

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if( Mengine::Helper::AppleHasBundlePluginConfig(@"MengineAppleAppLovinPlugin") == NO )
if( Mengine::Helper::AppleHasBundlePluginConfig(PLUGIN_BUNDLE_NAME) == NO )
{
NSLog(@"AppLovin plugin not found bundle config [%@]", PLUGIN_BUNDLE_NAME);

return NO;
}

NSString * MengineAppleAppLovinPlugin_IsAgeRestrictedUser = Mengine::Helper::AppleGetBundlePluginConfigString(@"MengineAppleAppLovinPlugin", @"IsAgeRestrictedUser", @"UNKNOWN");
NSString * MengineAppleAppLovinPlugin_IsAgeRestrictedUser = Mengine::Helper::AppleGetBundlePluginConfigString(PLUGIN_BUNDLE_NAME, @"IsAgeRestrictedUser", @"UNKNOWN");

if( [MengineAppleAppLovinPlugin_IsAgeRestrictedUser caseInsensitiveCompare:@"YES"] == NSOrderedSame )
{
Expand All @@ -31,10 +42,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
else
{
NSLog(@"AppLovin plugin invalid config [%@.IsAgeRestrictedUser] value %@ [YES|NO|UNKNOWN]", PLUGIN_BUNDLE_NAME, MengineAppleAppLovinPlugin_IsAgeRestrictedUser);

return NO;
}

NSString * MengineAppleAppLovinPlugin_CCPA = Mengine::Helper::AppleGetBundlePluginConfigString(@"MengineAppleAppLovinPlugin", @"CCPA", @"UNKNOWN");
NSString * MengineAppleAppLovinPlugin_CCPA = Mengine::Helper::AppleGetBundlePluginConfigString(PLUGIN_BUNDLE_NAME, @"CCPA", @"UNKNOWN");

if( [MengineAppleAppLovinPlugin_CCPA caseInsensitiveCompare:@"YES"] == NSOrderedSame )
{
Expand All @@ -50,28 +63,39 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
else
{
NSLog(@"AppLovin plugin invalid config [%@.CCPA] value %@ [YES|NO|UNKNOWN]", PLUGIN_BUNDLE_NAME, MengineAppleAppLovinPlugin_CCPA);

return NO;
}

ALSdkSettings * settings = [[ALSdkSettings alloc] init];

BOOL MengineAppleAppLovinPlugin_Verbose = Mengine::Helper::AppleGetBundlePluginConfigBoolean(@"MengineAppleAppLovinPlugin", @"Verbose", NO);
BOOL MengineAppleAppLovinPlugin_Verbose = Mengine::Helper::AppleGetBundlePluginConfigBoolean(PLUGIN_BUNDLE_NAME, @"Verbose", NO);

if( MengineAppleAppLovinPlugin_Verbose == YES )
{
settings.verboseLoggingEnabled = YES;
}

BOOL MengineAppleAppLovinPlugin_TermsAndPrivacyPolicyFlow = Mengine::Helper::AppleGetBundlePluginConfigBoolean(@"MengineAppleAppLovinPlugin", @"TermsAndPrivacyPolicyFlow", NO);
BOOL MengineAppleAppLovinPlugin_TermsAndPrivacyPolicyFlow = Mengine::Helper::AppleGetBundlePluginConfigBoolean(PLUGIN_BUNDLE_NAME, @"TermsAndPrivacyPolicyFlow", NO);

if( MengineAppleAppLovinPlugin_TermsAndPrivacyPolicyFlow == YES )
{
NSString * MengineAppleAppLovinPlugin_PrivacyPolicyURL = Mengine::Helper::AppleGetBundlePluginConfigString(@"MengineAppleAppLovinPlugin", @"PrivacyPolicyURL", nil);
NSString * MengineAppleAppLovinPlugin_PrivacyPolicyURL = Mengine::Helper::AppleGetBundlePluginConfigString(PLUGIN_BUNDLE_NAME, @"PrivacyPolicyURL", nil);

NSString * MengineAppleAppLovinPlugin_TermsOfServiceURL = Mengine::Helper::AppleGetBundlePluginConfigString(PLUGIN_BUNDLE_NAME, @"TermsOfServiceURL", nil);

NSString * MengineAppleAppLovinPlugin_TermsOfServiceURL = Mengine::Helper::AppleGetBundlePluginConfigString(@"MengineAppleAppLovinPlugin", @"TermsOfServiceURL", nil);
if( MengineAppleAppLovinPlugin_PrivacyPolicyURL == nil )
{
NSLog(@"AppLovin plugin missed required config [%@.PrivacyPolicyURL]", PLUGIN_BUNDLE_NAME);

return NO;
}

if( MengineAppleAppLovinPlugin_PrivacyPolicyURL == nil || MengineAppleAppLovinPlugin_TermsOfServiceURL == nil )
if( MengineAppleAppLovinPlugin_TermsOfServiceURL == nil )
{
NSLog(@"AppLovin plugin missed required config [%@.TermsOfServiceURL]", PLUGIN_BUNDLE_NAME);

return NO;
}

Expand All @@ -80,20 +104,34 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
settings.termsAndPrivacyPolicyFlowSettings.termsOfServiceURL = [NSURL URLWithString: MengineAppleAppLovinPlugin_TermsOfServiceURL];
}

NSString * MengineAppleAppLovinPlugin_SdkKey = Mengine::Helper::AppleGetBundlePluginConfigString(@"MengineAppleAppLovinPlugin", @"SdkKey", nil);
NSString * MengineAppleAppLovinPlugin_SdkKey = Mengine::Helper::AppleGetBundlePluginConfigString(PLUGIN_BUNDLE_NAME, @"SdkKey", nil);

if( MengineAppleAppLovinPlugin_SdkKey == nil )
{
NSLog(@"AppLovin plugin missed required config [%@.SdkKey]", PLUGIN_BUNDLE_NAME);

return NO;
}

ALSdk * appLovinSdk = [ALSdk sharedWithKey:MengineAppleAppLovinPlugin_SdkKey settings:settings];

appLovinSdk.mediationProvider = @"max";

[[ALSdk shared] initializeSdkWithCompletionHandler:^(ALSdkConfiguration *configuration) {
[appLovinSdk initializeSdkWithCompletionHandler:^(ALSdkConfiguration *configuration) {
ALConsentFlowUserGeography consentFlowUserGeography = configuration.consentFlowUserGeography;
NSString * countryCode = configuration.countryCode;
ALAppTrackingTransparencyStatus appTrackingTransparencyStatus = configuration.appTrackingTransparencyStatus;
BOOL testModeEnabled = configuration.testModeEnabled;

NSLog(@"AppLovin plugin initialize complete");
NSLog(@"consent flow user geography: %ld", consentFlowUserGeography);
NSLog(@"country code: %@", countryCode);
NSLog(@"app tracking transparency status: %ld", appTrackingTransparencyStatus);
NSLog(@"test mode enabled: %d", testModeEnabled);
}];

AppleAppLovinApplicationDelegate.AppLovinSdk = appLovinSdk;

return YES;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Plugins/AppleAppLovinPlugin/AppleAppLovinBannerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

@interface AppleAppLovinBannerDelegate : AppleAppLovinBaseDelegate<MAAdRequestDelegate, MAAdViewAdDelegate, MAAdRevenueDelegate>

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
placement:(NSString * _Nonnull) placement
amazonSlotId:(NSString * _Nullable) amazonSlotId
rect:(CGRect) rect
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
placement:(NSString * _Nonnull) placement
amazonSlotId:(NSString * _Nullable) amazonSlotId
rect:(CGRect) rect
provider:(const Mengine::AppleAppLovinBannerProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics;
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics;

- (void) show;
- (void) hide;
Expand Down
29 changes: 22 additions & 7 deletions src/Plugins/AppleAppLovinPlugin/AppleAppLovinBannerDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,36 @@

#include "Environment/iOS/iOSDetail.h"

#include "AppleAppLovinApplicationDelegate.h"

#include "Kernel/Logger.h"

@implementation AppleAppLovinBannerDelegate

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
placement:(NSString * _Nonnull) placement
amazonSlotId:(NSString * _Nullable) amazonSlotId
rect:(CGRect) rect
provider:(const Mengine::AppleAppLovinBannerProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics {
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
placement:(NSString * _Nonnull) placement
amazonSlotId:(NSString * _Nullable) amazonSlotId
rect:(CGRect) rect
provider:(const Mengine::AppleAppLovinBannerProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics {
self = [super initWithAdUnitIdentifier:adUnitId adFormat:MAAdFormat.banner analytics:analytics];

self.m_provider = provider;

MAAdView * adView = [[MAAdView alloc] initWithAdUnitIdentifier:adUnitId];
MAAdView * adView;

@try {
adView = [[MAAdView alloc] initWithAdUnitIdentifier:adUnitId sdk:AppleAppLovinApplicationDelegate.AppLovinSdk];
} @catch (NSException * ex) {
LOGGER_ERROR( "[Error] AppleAppLovinBannerDelegate invalid create MAAdView adUnitId: %s exception: %s [%s]"
, [adUnitId UTF8String]
, [ex.reason UTF8String]
, [ex.name UTF8String]
);

return nil;
}

[adView setPlacement:placement];

adView.delegate = self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@interface AppleAppLovinBaseDelegate : NSObject

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
adFormat:(MAAdFormat * _Nonnull) adFormat
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@implementation AppleAppLovinBaseDelegate

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
adFormat:(MAAdFormat * _Nonnull) adFormat
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics {
self = [super init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

@interface AppleAppLovinInterstitialDelegate : AppleAppLovinBaseDelegate<MAAdRequestDelegate, MAAdDelegate, MAAdRevenueDelegate>

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinInterstitialProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics;
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinInterstitialProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics;

- (BOOL) canYouShow:(NSString * _Nonnull) placement;
- (BOOL) show:(NSString * _Nonnull) placement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@
#include "Environment/Apple/AppleString.h"
#include "Environment/Apple/AppleAnalytics.h"

#include "AppleAppLovinApplicationDelegate.h"

#include "Kernel/Logger.h"
#include "Kernel/AnalyticsHelper.h"

@implementation AppleAppLovinInterstitialDelegate

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinInterstitialProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics {
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinInterstitialProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics {
self = [super initWithAdUnitIdentifier:adUnitId adFormat:MAAdFormat.rewarded analytics:analytics];

self.m_provider = provider;

MAInterstitialAd * interstitialAd = [[MAInterstitialAd alloc] initWithAdUnitIdentifier:adUnitId];
MAInterstitialAd * interstitialAd;

@try {
interstitialAd = [[MAInterstitialAd alloc] initWithAdUnitIdentifier:adUnitId sdk:AppleAppLovinApplicationDelegate.AppLovinSdk];
} @catch (NSException * ex) {
LOGGER_ERROR( "[Error] AppleAppLovinInterstitialDelegate invalid create MAInterstitialAd adUnitId: %s exception: %s [%s]"
, [adUnitId UTF8String]
, [ex.reason UTF8String]
, [ex.name UTF8String]
);

return nil;
}

interstitialAd.delegate = self;
interstitialAd.revenueDelegate = self;
interstitialAd.requestDelegate = self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

@interface AppleAppLovinRewardedDelegate : AppleAppLovinBaseDelegate<MAAdRequestDelegate, MARewardedAdDelegate, MAAdRevenueDelegate>

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinRewardedProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics;
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinRewardedProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics;

- (BOOL) canOffer:(NSString * _Nonnull) placement;
- (BOOL) canYouShow:(NSString * _Nonnull) placement;
Expand Down
25 changes: 20 additions & 5 deletions src/Plugins/AppleAppLovinPlugin/AppleAppLovinRewardedDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,34 @@
#include "Environment/Apple/AppleString.h"
#include "Environment/Apple/AppleAnalytics.h"

#include "AppleAppLovinApplicationDelegate.h"

#include "Kernel/Logger.h"

@implementation AppleAppLovinRewardedDelegate

- (instancetype _Nonnull) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinRewardedProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics {
- (instancetype _Nullable) initWithAdUnitIdentifier:(NSString * _Nonnull) adUnitId
amazonSlotId:(NSString * _Nullable) amazonSlotId
provider:(const Mengine::AppleAppLovinRewardedProviderInterfacePtr &) provider
analytics:(AppleAppLovinAnalyticsService * _Nonnull) analytics {
self = [super initWithAdUnitIdentifier:adUnitId adFormat:MAAdFormat.interstitial analytics:analytics];

self.m_provider = provider;

MARewardedAd * rewardedAd = [MARewardedAd sharedWithAdUnitIdentifier: adUnitId];
MARewardedAd * rewardedAd;

@try {
rewardedAd = [MARewardedAd sharedWithAdUnitIdentifier: adUnitId sdk:AppleAppLovinApplicationDelegate.AppLovinSdk];
} @catch (NSException * ex) {
LOGGER_ERROR( "[Error] AppleAppLovinRewardedDelegate invalid create MARewardedAd adUnitId: %s exception: %s [%s]"
, [adUnitId UTF8String]
, [ex.reason UTF8String]
, [ex.name UTF8String]
);

return nil;
}

rewardedAd.delegate = self;
rewardedAd.requestDelegate = self;
rewardedAd.revenueDelegate = self;
Expand Down
15 changes: 15 additions & 0 deletions src/Plugins/AppleAppLovinPlugin/AppleAppLovinService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
provider:_provider
analytics:m_analyticsService];

if( banner == nil )
{
return false;
}

[m_banners setValue:banner forKey:adUnitId];

return true;
Expand Down Expand Up @@ -153,6 +158,11 @@
provider:_provider
analytics:m_analyticsService];

if( interstitial == nil )
{
return false;
}

[m_interstitials setValue:interstitial forKey:adUnitId];

return true;
Expand Down Expand Up @@ -213,6 +223,11 @@
provider:_provider
analytics:m_analyticsService];

if( rewarded == nil )
{
return false;
}

[m_rewardeds setValue:rewarded forKey:adUnitId];

return true;
Expand Down
2 changes: 2 additions & 0 deletions src/SDLApplication/SDLUIApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

for (id delegate in self.m_pluginDelegates) {
if ([delegate application:application didFinishLaunchingWithOptions:launchOptions] == NO) {
NSLog(@"Mengine application initialize plugin %@ failed", NSStringFromClass([delegate class]));

return NO;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/SDLApplication/iOSMain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ int main( int argc, char * argv[] ) {
int result;

@autoreleasepool {
result = UIApplicationMain(argc, argv, nil, NSStringFromClass([SDLUIApplicationDelegate class]));
@try {
result = UIApplicationMain(argc, argv, nil, NSStringFromClass([SDLUIApplicationDelegate class]));
} @catch (NSException * ex) {
result = EXIT_FAILURE;

NSLog(@"Exception Megnine application: %@ [%@]", ex.description, ex.reason);
}
}

NSLog(@"Finish Megnine application: %d", result);
Expand Down
Loading

0 comments on commit 2d055aa

Please sign in to comment.