Working In-App Purchases for iOS

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Working In-App Purchases for iOS

Post by slime »

raidho36 wrote:Maybe this can be implemented as core functionality instead, given that it's a fairly standard feature for mobile apps.
That is partly why spill shared this, I believe. :)
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Working In-App Purchases for iOS

Post by raidho36 »

Now to implement something similar for Android... Given enough effort that could show up in the next minor version.
User avatar
spill
Prole
Posts: 27
Joined: Thu May 07, 2015 1:53 am
Contact:

Re: Working In-App Purchases for iOS

Post by spill »

raidho36 wrote:Now to implement something similar for Android... Given enough effort that could show up in the next minor version.
That's what I'm currently working on. Right now, I'm trying to figure out how to add the appropriate billing helper module and wrap my head around the Android dev environment. Based on the iOS experience, it should take a couple of weeks to get it finished. In my ideal world, purchasing would be built into löve by default, and hopefully this work will lead to that, or at least help anyone else who wants to do IAP in the meantime.
bartbes wrote:Love's event queue is thread-safe, and you don't have to predeclare events either, that might be a good option.
I'd prefer suspending the lua code execution on the API call and returning the result of the purchase once it's finished (like love.window.showMessageBox() does) instead of having an SDL event because it makes the code a lot cleaner, as you can see here:

Code: Select all

function button:onPressed()
    if love.system.makePurchase("foo.baz.item1") == "success" then
        ITEM1_UNLOCKED = true
    end
end
vs.

Code: Select all

function button:onPressed()
    pauseGame()
    love.system.makePurchase("foo.baz.item1")
end
local dispatchTable = {
    ["foo.baz.item1"]=function(status)
        unpauseGame()
        if status == "success" then
            ITEM1_UNLOCKED = true
        end
    end,
}
function love.purchased(purchaseID, status)
    if dispatchTable[purchaseID] then dispatchTable[purchaseID](status) end
end
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Working In-App Purchases for iOS

Post by raidho36 »

On the flipsede it freezes the game for the whole duration, which may be a lot, especially if it has to timeout - up to 2 minutes. Freezing the app alone creates poor user experience since it becomes unresponsive and there is no progress indication, and sophisticated OS can detect it as hang (because that's what it is) and suggest kill the app or even do it automatically.

IAPs are fundamentally networking activity and you never do synchronous networking, period.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Working In-App Purchases for iOS

Post by zorg »

raidho36 wrote:On the flipsede it freezes the game for the whole duration, which may be a lot, especially if it has to timeout - up to 2 minutes. Freezing the app alone creates poor user experience since it becomes unresponsive and there is no progress indication, and sophisticated OS can detect it as hang (because that's what it is) and suggest kill the app or even do it automatically.

IAPs are fundamentally networking activity and you never do synchronous networking, period.
zorg wrote:Okay, but one could just not use the modal messagebox function, and just implement a visual one with löve itself, that way it may not block. (i.e. not freeze the whole game)
Spill wrote:Actually no, Apple doesn't let you do that. Presumably in order to prevent apps from making deceptive or confusing purchase dialogs (or stealing the user's credentials, maybe?), the only way to make a purchase through Apple involves using their native purchase modal dialog. There's no way to request a purchase without popping one up. It also fills in the region/currency-specific pricing, which is something you wouldn't want to do by hand.
¯\_(ツ)_/¯
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Working In-App Purchases for iOS

Post by Nixola »

I think he said Apple doesn't let you implement a visual purchasing window or anything, and you have to call the function to have the OS "window" pop up and request a purchase; that doesn't mean the background application has to hang, as you can draw a "working..." animation/something while the purchase is completed.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Working In-App Purchases for iOS

Post by slime »

Theoretically you can. But SDL's messagebox API is always blocking even though iOS allows for non-blocking message boxes, so you'd have to use the native iOS Objective-C APIs for it instead of SDL.
gianmichele
Citizen
Posts: 66
Joined: Tue Jan 14, 2014 11:03 pm

Re: Working In-App Purchases for iOS

Post by gianmichele »

Hey, thanks a lot for this!

It's actually really good to study how to implement these different services.
I'm quite curious to see how the implementation would be using FFI. Keep hearing people it's a possible solution, but I haven't seen anything properly done this way yet (I mean a service like Vungle or Game Center). Just small examples of simple libraries.

@slime: hint hint a good tutorial would be great.

In the meantime I'm going to experiment and try and wrap Vungle or Unity Ads to see if I can work it out. Wish me luck!


Gian
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests