Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Ad is showing only one time?
Started by tppellegrini2 Oct 02 2018 09:46 AM

7 replies to this topic
ads corona app ios problem
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

tppellegrini2

[GLOBAL: userInfoPane.html]
tppellegrini2
  • Observer

  • 5 posts
  • Corona SDK

So, I implemented monetization through Appodeal, but i'm having a strange issue: the ad is showing up only when I launch the game for the first time! I know that code outside the scene events is going to be run only one time, and that's why I call the function to show the ad in the scene:show and hide it in the scene:hide. 

But when I move to another scene and then go back to my "menu" scene, which is where I want the ad to show up, it doesn't. Any ideas ? 

Thanks.



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,970 posts
  • Corona Staff

I would suggest you read this blog post and the associated tutorial.

 

https://coronalabs.com/blog/2018/10/02/monetization-best-practices-and-a-new-ad-tutorial/

 

Rob



[TOPIC: post.html]
#3

tppellegrini2

[GLOBAL: userInfoPane.html]
tppellegrini2
  • Observer

  • 5 posts
  • Corona SDK

I followed it already, look I'll paste some of my code. 

function scene:show(event)

	local sceneGroup = self.view
	local phase = event.phase

	if ( phase == "will" ) then
		-- Code here runs when the scene is still off screen (but is about to come on screen)
	
		local menumusic
		menumusic = audio.loadStream("audio/menumusic.mp3")
		audio.play(menumusic, {loops=-1})

		--------SHOW AD----------
		local appodeal = require( "plugin.appodeal" )

		local function adListener( event )

			if ( event.phase == "init" ) then  -- Successful initialization
				-- Show a banner ad
				appodeal.show( "banner", { yAlign="top" } )

			elseif ( event.phase == "failed" ) then  -- The ad failed to load
				print( event.type )
				print( event.isError )
				print( event.response )
			end
		end

		-- Initialize the Appodeal plugin
		appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } )
		-------------------------
	
	elseif ( phase == "did" ) then
		-- Code here runs when the scene is entirely on screen	
		local menumusic
		menumusic = audio.loadStream("audio/menumusic.mp3")
		audio.play(menumusic, {loops=-1})

		--------SHOW AD----------
		local appodeal = require( "plugin.appodeal" )

		local function adListener( event )

			if ( event.phase == "init" ) then  -- Successful initialization
				-- Show a banner ad
				appodeal.show( "banner", { yAlign="top" } )

			elseif ( event.phase == "failed" ) then  -- The ad failed to load
				print( event.type )
				print( event.isError )
				print( event.response )
			end
		end

		-- Initialize the Appodeal plugin
		appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } )
		-------------------------
	end
end

I actually have it, as you can see, both on will and on did. The fact is, if I delete the "will", the ad doesn't pop up at all. 

If I leave it on will, or even both of them, the ad will show up, go away because I hide it in the scene:hide(event) but won't reappear after I come back to the menu scene. 

 

EDIT: 

I tried removing totally the "will" phase and leave just the "did" phase and it works, but the ad still doesn't pop when I go back to the menu. 

 

EDIT 2: 

Apparently I just can't have it in the scene:show(event). 

What I said applies only if I leave the code in the scene:create for some reasons. 

 

EDIT 3: 

Also, why do you give me a guide where the code is for admob?



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,970 posts
  • Corona Staff

You apparently missed a very key point in the tutorial:

 

"Initialization should only happen once. This is best done in main.lua, but for more advanced setups, you could create a module to hold your advertising code and require that module in main.lua, but for most, you will do all of this in main.lua."

 

You should not be initializing the plugin in a scene. The only thing a scene should do is show an ad, hide if necessary, and load the next ad. 

 

Rob



[TOPIC: post.html]
#5

tppellegrini2

[GLOBAL: userInfoPane.html]
tppellegrini2
  • Observer

  • 5 posts
  • Corona SDK

I removed the other initializations but the problems persists: I can clearly see from the console that if I paste the command 

appodeal.show( "banner", { yAlign="top" } ) 

in the scene:create(event) the function will be called. However if I put it in the scene:show(event) it won't be called in the console. 



[TOPIC: post.html]
#6

tppellegrini2

[GLOBAL: userInfoPane.html]
tppellegrini2
  • Observer

  • 5 posts
  • Corona SDK

I managed to get it called buy the console, using just the command appeal.show() but still, even if in console everything seems to work, once I build it for the device the ad won't pop up. 



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,970 posts
  • Corona Staff

I'm not sure what you mean by "I managed to get it called by the console". Can you clarify?

 

Can you post your current code?

 

Rob



[TOPIC: post.html]
#8

tppellegrini2

[GLOBAL: userInfoPane.html]
tppellegrini2
  • Observer

  • 5 posts
  • Corona SDK

I solved it. To be honest I am not a hundred percent sure how I did it, but I am pretty sure I was doing something wrong in the init of the Appodeal plugin in my main and it wasn't able to call properly the show functions, even though everything appeared in the console. 
I also made some changes to the scene:show() did part and that worked too. 

Thank you for the help anyways. 

 

You can mark as solved, I will now post my code so if someone has troubles they could refer to this: 

ALSO I HIGHLY SUGGEST TO REMOVE YANDEX AS IT STILL CAUSE iOS REJECTION

 

My settings 

	plugins =
    {	
		-- Base
		['plugin.appodeal.base'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.AmazonAds'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.GoogleAdMob'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.TwitterMoPub'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.StartApp'] = { publisherId = 'com.coronalabs' },
		-- Banner
		['plugin.appodeal.AppLovin'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.FacebookAudience'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.Flurry'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.InMobi'] = { publisherId = 'com.coronalabs' },
		['plugin.appodeal.MyTarget'] = { publisherId = 'com.coronalabs' },
    },

My main


local function adListener( event )
 
    if ( event.phase == "init" ) then  -- Successful initialization
        print( event.isError )
    end
end
 
-- Initialize the Appodeal plugin
appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } )

My scene 

elseif ( phase == "did" ) then
		
		--[...other code of mine was here...]
		appodeal.show( "banner", { yAlign="top" } ) 
	
	end

And then I just called Appodeal.hide in the hide scene. 




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: ads, corona, app, ios, problem