I have recently implemented IAP, but for some reason the transaction keeps failing, and I keep getting the error “Cannot Connect to iTunes”. Is there something wrong wit my code?
PS: my IAP product id is “ChowDownDeleteAds”
[lua]–Initialize in app purchases
local function popUpDismiss (event)
if “clicked” == event.action then
local i = event.index
if 1 == i then
end
end
end
store = require(“store”)
function transactionCallback( event )
local transaction = event.transaction
if transaction.state == “purchased” then
saveFile(“adsHidden.txt”, 0)
print(“Transaction succuessful!”)
local alert = native.showAlert( “Purchase Completed!”, “All ads were hidden!”, { “OK”}, popUpDismiss )
elseif transaction.state == “restored” then
print(“Transaction restored (from previous session)”)
print(“productIdentifier”, transaction.productIdentifier)
print(“receipt”, transaction.receipt)
print(“transactionIdentifier”, transaction.identifier)
print(“date”, transaction.date)
print(“originalReceipt”, transaction.originalReceipt)
print(“originalTransactionIdentifier”, transaction.originalIdentifier)
print(“originalDate”, transaction.originalDate)
elseif transaction.state == “cancelled” then
local alert = native.showAlert( “Purchase Cancelled!”, “Purchase was cancelled by the user.”, { “OK”}, popUpDismiss )
elseif transaction.state == “failed” then
local alert = native.showAlert(“Purchase Failed!” , transaction.errorType… ": " …transaction.errorString, { “OK”}, popUpDismiss )
end
– Once we are done with a transaction, call this to tell the store
– we are done with the transaction.
– If you are providing downloadable content, wait to call this until
– after the download completes.
store.finishTransaction( transaction )
end
store.init( transactionCallback )
local hideAdsTitle
local hideAdsPrice
local function loadHideAdsInfo( event )
local hideAds = event.products
hideAdsTitle = hideAds.title
hideAdsPrice = hideAds.price
end
print(hideAdsTitle)
local hideAdsID =
{
“ChowDownDeleteAds”
}
store.loadProducts(hideAdsID,loadHideAdsInfo)
local function popUpResponse(event)
if “clicked” == event.action then
local i = event.index
if 1 == i then
elseif 2 == i then
store.purchase( hideAdsID )
end
end
end
print(adsHidden)
if adsHidden == “0” then
local hideAdsBtn = display.newImage(“troll.jpg”, true)
localGroup:insert(hideAdsBtn)
local function touchHideAdsBtn (event)
if adsHidden == “0” then
if event.phase == “began” then
local alert = native.showAlert( “Hide Ads”, “Would you like to hid all ads for only $0.99?”, { “Cancel”, “OK” }, popUpResponse )
end
end
end
hideAdsBtn:addEventListener (“touch”, touchHideAdsBtn)
end[/lua] [import]uid: 130035 topic_id: 23489 reply_id: 323489[/import]