Skip to content

Commit

Permalink
fix #37
Browse files Browse the repository at this point in the history
  • Loading branch information
AGulev committed Nov 7, 2023
1 parent ef7460f commit 656e8a5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
3 changes: 2 additions & 1 deletion extension-admob/src/admob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace dmAdmob {

static const char DEFOLD_USERAGENT[] = "defold-3.2.0";
static const char DEFOLD_USERAGENT[] = "defold-3.3.1";

static int Lua_Initialize(lua_State* L)
{
Expand Down Expand Up @@ -263,6 +263,7 @@ static dmExtension::Result InitializeAdmob(dmExtension::Params* params)

static dmExtension::Result AppFinalizeAdmob(dmExtension::AppParams* params)
{
Finalize_Ext();
return dmExtension::RESULT_OK;
}

Expand Down
4 changes: 4 additions & 0 deletions extension-admob/src/admob_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ void Initialize_Ext()
g_admob.m_AdmobJNI = env->NewGlobalRef(env->NewObject(cls, jni_constructor, threadAttacher.GetActivity()->clazz));
}

void Finalize_Ext()
{
}

void Initialize(const char* defoldUserAgent)
{
CallVoidMethodChar(g_admob.m_AdmobJNI, g_admob.m_Initialize, defoldUserAgent);
Expand Down
41 changes: 40 additions & 1 deletion extension-admob/src/admob_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ @interface AdmobExtRewardedAdDelegate : NSObject<GADFullScreenContentDelegate>
@interface AdmobExtBannerAdDelegate : NSObject<GADBannerViewDelegate>
@end

@interface AdMobAppDelegate : NSObject <UIApplicationDelegate>
@end

namespace dmAdmob {

static const char* m_DefoldUserAgent = nil;

static UIViewController *uiViewController = nil;
static AdMobAppDelegate *admobAppDelegate = nil;

void SendSimpleMessage(MessageId msg, id obj) {
NSError* error;
Expand Down Expand Up @@ -316,6 +320,10 @@ void UpdatePosition(BannerPosition bannerSizeConst) {
bannerAd.center = bannerPos;
}

void UpdatePosition() {
UpdatePosition(lastBannerPos);
}

bool IsBannerLoaded() {
return bannerAd != nil;
}
Expand All @@ -342,7 +350,7 @@ void ShowBanner(BannerPosition bannerPos) {
if (bannerPos != POS_NONE) {
lastBannerPos = bannerPos;
}
UpdatePosition(lastBannerPos);
UpdatePosition();
}
}

Expand Down Expand Up @@ -373,6 +381,17 @@ void Initialize_Ext() {
admobExtInterstitialAdDelegate = [[AdmobExtInterstitialAdDelegate alloc] init];
admobExtRewardedAdDelegate = [[AdmobExtRewardedAdDelegate alloc] init];
admobExtBannerAdDelegate = [[AdmobExtBannerAdDelegate alloc] init];
admobAppDelegate = [[AdMobAppDelegate alloc] init];

dmExtension::RegisteriOSUIApplicationDelegate(admobAppDelegate);
}

void Finalize_Ext() {
dmExtension::UnregisteriOSUIApplicationDelegate(admobAppDelegate);
[admobExtInterstitialAdDelegate dealloc];
[admobExtRewardedAdDelegate dealloc];
[admobExtBannerAdDelegate dealloc];
[admobAppDelegate dealloc];
}

void SetPrivacySettings(bool enable_rdp) {
Expand Down Expand Up @@ -530,4 +549,24 @@ - (void)bannerViewDidRecordClick:(GADBannerView *)bannerView {

@end

@implementation AdMobAppDelegate

- (instancetype)init {
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
return self;
}

- (void) UpdatePosition {
dmAdmob::UpdatePosition();
}

- (void)orientationDidChange:(NSNotification *)notification {
[self performSelector:@selector(UpdatePosition) withObject:nil afterDelay:0.1];
}

@end

#endif
1 change: 1 addition & 0 deletions extension-admob/src/admob_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum MaxAdRating
};

void Initialize_Ext();
void Finalize_Ext();

void Initialize(const char* defoldUserAgent);
void LoadInterstitial(const char* unitId);
Expand Down
2 changes: 1 addition & 1 deletion main/ads.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function on_input(self, action_id, action)
admob.show_rewarded()
elseif self.ad_type == admob.MSG_BANNER then
if self.is_banner_shown then
print("admob.show_banner(admob."..self.banner_positions[self.show_pos]..") --("..self.show_pos..")")
print("admob.show_banner( admob."..self.banner_positions[self.show_pos]..") --("..self.show_pos..")")
admob.show_banner(admob[self.banner_positions[self.show_pos]])
self.show_pos = self.show_pos + 1
if self.show_pos > #self.banner_positions then
Expand Down

0 comments on commit 656e8a5

Please sign in to comment.