Hello!
My app is almost ready to be submitted but I have a nasty bug I have no idea where it comes from.
So here’s what happening :
- When touching the “purchase” button, the Apple password pop-up appears and ask for the password
- The app crashes as soon as the pop-up appears
- The pop-up stays and it’s possible to enter the password
- When re-launching the app, the coins purchased has been added to the account.
I’m using build 2012.777
Thanks for your help!
Here’s my code :
[lua]---------------------------------------------------------------
– IAP MANAGER
local IAPManager = {}
– MODULES
local store = require(“store”)
– VARS
local isPurchaseSuccess = false
local bankCallBack = nil
local IAPList = {}
—[[
local productValue = {
[“productId.001”] = { “coin”, 2000 },
[“productId.001”] = { “technoPoint”, 10 },
[“productId.001”] = { “coin”, 20000 },
[“productId.001”] = { “technoPoint”, 100 },
[“productId.001”] = { “coin”, 100000 },
[“productId.001”] = { “technoPoint”, 500 },
}
–]]
– FUNCTIONS
– IAP INIT
function IAPManager.init()
local function storeCallBack(e)
isPurchaseSuccess = false
local t = e.transaction
if t.state == “purchased” then
–native.showAlert( “Success”, t.state, { “OK” } )
– Store purchase
local purchaseData = productValue[t.productIdentifier]
SM.logIAP( “iap”, purchaseData[1], purchaseData[2] )
– Disable ads
local settings = ice:loadBox( “Settings” )
local settingsData = settings:retrieve( “data” )
if settingsData.ads then
Ads = false
settingsData.ads = false
settings:store( “data”, settingsData )
settings:save()
end
isPurchaseSuccess = true
elseif t.state == “restored” then
–native.showAlert( “Restored”, t.state, { “OK” } )
elseif t.state == “refunded” then
– Only available on Android
–native.showAlert( “Refunded”, t.state, { “OK” } )
elseif t.state == “cancelled” then
–native.showAlert( “Cancelled”, t.state, { “OK” } )
elseif t.state == “failed” then
native.showAlert( t.errorType, t.errorString, { “OK” } )
else
native.showAlert( “Error”, “Unknow error”, { “OK” } )
end
store.finishTransaction( t )
– Bank callback
if bankCallBack then
bankCallBack( isPurchaseSuccess )
bankCallBack = nil
end
end
print(“Store init”)
store.init(storeCallBack)
end
– LOAD PRODUCTS
function IAPManager.getProducts(buildScene)
local function onLoadProducts(e)
IAPList = IAPManager.getIAPList( e.products )
if buildScene then
buildScene( IAPList )
else
return IAPList
end
end
—[[
local productIds = {
“productId.001”,
“productId.002”,
“productId.003”,
“productId.004”,
“productId.005”,
“productId.006”
}
–]]
store.loadProducts(productIds, onLoadProducts)
end
– PURCHASE
function IAPManager.purchase(id, endTransaction)
if store.canMakePurchases then
bankCallBack = endTransaction
store.purchase({id})
else
local function callBack()
endTransaction( false )
end
local title = { [“en”]=“Error”, [“fr”]=“Erreur”, [“es”]=“Error”, [“de”]=“Error”, [“it”]=“Error” }
local body = {
[“en”]=“In-app purchases are disabled. Enable in-app purchases in settings.”,
[“fr”]=“Cet appareil n’est pas autorisé à effectuer des achats intégrés. Vous pouvez l’autoriser en allant dans les réglages.”,
[“es”]=“In-app purchases are disabled. Enable in-app purchases in settings.”,
[“de”]=“In-app purchases are disabled. Enable in-app purchases in settings.”,
[“it”]=“In-app purchases are disabled. Enable in-app purchases in settings.”
}
native.showAlert( title[lang], body[lang], { “OK” }, callBack )
end
end
– GET IAP LIST
function IAPManager.getIAPList( validProducts )
if #validProducts > 0 then
for i=1, #validProducts do
local p = validProducts[i]
IAPList[i] = {
id = p.productIdentifier,
desc = p.description,
iconPath = { p=“shopUI/”…p.productIdentifier…".jpg", w=110, h=53 },
price = p.localizedPrice,
itemType = productValue[p.productIdentifier][1],
unit = productValue[p.productIdentifier][2]
}
end
else
native.showAlert( “Error”, “No valid Products”, { “OK” } )
end
return IAPList
end
return IAPManager[/lua] [import]uid: 25327 topic_id: 31171 reply_id: 331171[/import]