Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Best way to structure code to work on Android AND iOS for leaderboards and monetization
Started by nml2727 Dec 17 2019 07:24 AM

- - - - -
3 replies to this topic
android ios monetization leaderboards
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 96 posts
  • Corona SDK

I need to add leaderboards as well as monetization code to my game.  I'm trying to figure out the best way to structure the code since Android and iOS are different.  

 

Can someone who has experience in this just give me a high level overview of the easiest way to set up the code?  

 

Do I create modules like   appleLeaderboard.lua, androidLeaderboard.lua, etc... and then just require and use functions based on if it's running on iOS or android?

 

Any other tips/tricks I should be aware of before?



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,175 posts
  • Corona SDK

The best practice tends to be that you write a single module that handles leaderboards for both OS, same with IAPs.

 

Then in the modules, all you need is system.getInfo( "platform" ) to identify which OS you are on. As you write functions like "purchase( args )", you'll need a simple if statement and then you run OS specific code.

 

The benefit in this sort of approach is that you'll be able to use the same function calls regardless of the OS, which makes implementing the module into your projects a lot easier. Now, there are some features that only exists for a specific OS (see https://docs.coronalabs.com/guide/monetization/IAP/index.html#store-specific) that you'd also need to take into account.


  • pixec likes this

[TOPIC: post.html]
#3

nml2727

[GLOBAL: userInfoPane.html]
nml2727
  • Enthusiast

  • 96 posts
  • Corona SDK

Ok, that makes sense.   Thanks XeduR @Spyric!



[TOPIC: post.html]
#4

GrahamRanson

[GLOBAL: userInfoPane.html]
GrahamRanson
  • Contributor

  • 124 posts
  • Corona SDK

If it helps at all, my Puggle library allows you to register achievements, leaderboards, and iaps for all platforms and then just call one function to unlock/purchase them regardless of platform - https://gitlab.com/grahamranson/Puggle
 

puggle.store:add( "removeAdverts", { apple = "com.website.removeads", google = "com.website.removeads", amazon = "com.website.removeads" } )

puggle.leaderboards:add( "hiScore", { android = "id", ios = "id" } )

puggle.achievements:add( "completedFirstLevel", { android = "id", ios = "id" } )


-- LATER ON

puggle.store:purchase( "removeAdverts" )

puggle.leaderboards:setHighScore( "hiScore", currentScore )

puggle.achievements:unlock( "completedFirstLevel" )



[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: android, ios, monetization, leaderboards