Cannot connect to Itunes Store, HELP

Hi everyone.

I’m trying to implement an In App Purchase. For that i create a new App in Itunes Connect and a new In App Purchase. These are in state “Waiting fot Upload” and “Ready to Submit”. I create a test user too.

When i try my code on device it gives me an error. “Failed: Cannot connect to Itunes Store”

I’m login with the test user.

This is my code.

  
display.setStatusBar( display.HiddenStatusBar )  
  
local loadsave = require("loadsave")  
local store = require("store")   
---FUNCIONES-----  
local unpackValidProducts, loadProductsCallback, savePurchase  
local transactionCallback, setupMyStore, onbuyButTap, onbuyButTap2  
local boton1, boton2, boton3  
  
descriptionArea = native.newTextBox (10, 0.7\*display.contentHeight, display.contentCenterX - 20, display.contentCenterY - 10)  
descriptionArea.text = "Select a product..."  
descriptionArea:setTextColor (2, 0, 127)  
descriptionArea.size = 18  
descriptionArea.hasBackground = false  
function onbuyButTap2()  
 descriptionArea.text = "onbuyButTap2"  
  
 if store.canMakePurchases then  
 store.purchase( {"com.Bilu.diferenciasTest.fullversion123" } )  
 else  
 native.showAlert("Store purchases are not available, please try again later", { "OK" } )   
 end   
end   
  
function onbuyButTap()  
 descriptionArea.text = "onbuyButTap"  
  
 boton1:removeEventListener("tap", onbuyButTap)  
 boton1.alpha = 0.4  
 boton2.alpha = 1  
 boton2:addEventListener("tap", onbuyButTap2)  
  
 --if store.canMakePurchases then  
 store.restore()  
 -- store.purchase( {"com.Bilu.diferenciasTest.fullversion123" } )  
 --else  
 -- native.showAlert("Store purchases are not available, please try again later", { "OK" } )   
 --end   
end   
  
local estado = loadTable("estado.json")  
  
 if estado == nil then  
 estado = "sincompra"  
 saveTable(estado,"estado.json")  
 end  
boton1 = display.newImage( "comprar.png", 50, 50 )  
boton2 = display.newImage( "comprar2.png", 50, 170 )  
boton3 = display.newImage( "listo.png", 300, 300 )  
  
if estado == "sincompra" then  
 boton2.alpha = 0.4  
 boton3.alpha = 0.4  
 boton1:addEventListener("tap", onbuyButTap)  
elseif estado == "comprado" then  
 boton1.alpha = 0.4  
 boton2.alpha = 0.4  
end  
  
local listOfProducts = {   
 "com.Bilu.diferenciasTest.fullversion123",   
 }   
local validProducts, invalidProducts = {}, {}  
  
  
function unpackValidProducts()  
 print ("Loading product list")  
 if not validProducts then  
 native.showAlert( "In-App features not available", "initStore() failed", { "OK" } )   
 else  
 for i=1, #invalidProducts do  
 native.showAlert( "Item " .. invalidProducts[i] .. " is invalid.",{ "OK" } )  
 end  
 end  
end  
function loadProductsCallback( event )  
 validProducts = event.products  
 invalidProducts = event.invalidProducts   
 unpackValidProducts ()  
end  
  
function savePurchase(product)  
 estado = "comprado"  
 saveTable(estado,"estado.json")  
 boton2:removeEventListener("tap", onbuyButTap2)  
 boton2.alpha = 0.4  
end  
  
function transactionCallback( event )  
  
 --descriptionArea.text = "Transaction failed, type: " .. event.transaction.errorType .. "String:" .. event.transaction.errorString  
 --local alert = native.showAlert("Estado", event.transaction.state,{ "OK" })  
  
 if event.transaction.state == "purchased" then   
 descriptionArea.text = "purchsed"  
 savePurchase("product")   
  
 elseif event.transcation.state == "restored" then   
 descriptionArea.text = "restored"  
 savePurchase("product")  
  
 elseif event.transaction.state == "cancelled" then  
 descriptionArea.text = "cancelled"  
  
 elseif event.transaction.state == "failed" then   
 descriptionArea.text = "failed"   
 --infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString  
 --local alert = native.showAlert("Failed ", infoString,{ "OK" })  
  
 else  
 descriptionArea.text = "Unknow"  
  
 end  
  
 store.finishTransaction( event.transaction )  
end  
  
function setupMyStore (event)  
 store.loadProducts( listOfProducts, loadProductsCallback )  
end  
  
store.init(transactionCallback)   
timer.performWithDelay (1000, setupMyStore)  
  

[import]uid: 105206 topic_id: 25314 reply_id: 325314[/import]

@nml, do you know how far your IAP executes and where it fails? When I had trouble with IAP, what I did was add print statements inside every single function (at the start and the end of the function). I might’ve added print statements inside if-statements too. This way, I’d know where things go wrong. Once you know which step is failing, it’s much easier to debug.

Naomi

Edit: I also sort of remember having this “cannot connect to iTunes” message even after my IAP became totally stable and working perfectly. If your IAP never worked so far, it probably isn’t caused by the same issue, though. (In my case, I just had to wipe clean my test device, and it always returned everything back to normal – but that’s a very drastic measure and I wouldn’t recommend it…)

Good luck! [import]uid: 67217 topic_id: 25314 reply_id: 102279[/import]

Hi Naomi, thanks for the answer!

What happen is something strange.
I add print statements to verify how far executes. It reachs the function transactionCallback and when i print “event.transaction.state” it gaves me a “failed” state. However, it never enter to the “elseif event.transaction.state == “failed” then”.

On the device appears the login box, but after that nothing happen.

Is there any problem if the In App Purchase state is “Ready to Submit”?

Thank you!
[import]uid: 105206 topic_id: 25314 reply_id: 102345[/import]

Hey, @nml, my In App Purchase state was in Ready to Submit state forever and ever, and I was still able to have the test users make purchases. So, Ready to Submit state shouldn’t be an issue.

You might want to print event.transaction.errorType and event.transaction.errorString and see what it says. It might give you some insight as to what’s going on:

[lua]print("event.transaction.errorType = " … tostring(event.transaction.errorType))
print("event.transaction.errorString = " … tostring(event.transaction.errorString))[/lua]

Naomi

Edit: I re-read your note above, and I’m wondering if descriptionArea.text is giving you any grief? No? Not sure why errorType returns “failed” but won’t proceed to go inside elseif for the “failed” event. Maybe you want to print event.transaction.state too?

Edit2: And you know what, your device might be in this strange state where my device sometimes finds itself in. You know, the state where it just can’t connect o iTunes Sandbox. Absolutely refuses to work with Sandbox. Mine sometimes does that, and I simply go ahead and wipe it clean, and it starts working without any issue whatsoever. Again, the first time I had to reset it, I really didn’t like the idea, but once I did it, it became a simple routine for me… [import]uid: 67217 topic_id: 25314 reply_id: 102359[/import]

I don’t have the device here to test it, but i remember that event.transaction.errorType and event.transaction.errorString gaves me “unknown” and “cannot connect to itunes store”.

I don’t understand what you mean about “wipe it clean” or “reset it”. Do you mean that i have to remove the prints?

Thank you for your answers, Naomi. [import]uid: 105206 topic_id: 25314 reply_id: 102414[/import]

Hey, @nml, when I wipe it clean (i.e., do the complete reset), this is what I do:

Settings > General > Reset > Erase All Content and Settings

When I do this, it gets my test device (iPod Touch) back to factory default. I don’t bother using iCloud or anything – so it’s plain simple process for me. If you have lots of things on your device and want to keep things the way they are, the process may not be as simple… I don’t want to do this with our old iPad, so I don’t bother testing IAP on it (not that it could be an issue – just that never wanted to deal with the process.)

I hope it helps. Best of luck!

Naomi

Edit: If you do wipe your device, remember to sign in using your real ID (not the test user account), and then, once it’s ready for testing, remember to sign out. Don’t sign in until your IAP asks you to sign in – and then, use your test user account to sign in (by tapping on Use Existing Account during the IAP purchase process).
[import]uid: 67217 topic_id: 25314 reply_id: 102427[/import]

Isn’t another way to do it? Because the device i’m using to test isn’t mine.

It couldn’t be an error in my code?

Thanks [import]uid: 105206 topic_id: 25314 reply_id: 102429[/import]

Hey, @nml, you could try creating new test user accounts at iTunes Connect, and try logging in using the new test user(s). You can use fake email addresses for test users. For example, if you own a domaine name, myWebSite.com, then you could create a test user test1@myWebSite.com, test2@myWebSite.com, test3@myWebStie.com, etc.

You could also try building sample IAP code (replacing the product ID with your own), and see if the problem persists.

Good luck.

Naomi [import]uid: 67217 topic_id: 25314 reply_id: 102601[/import]

Hi, Naomi. Thank you for the answers again.

I tried using fake email adress for a test user. But the problem persist.

I tried with the InAppDemo too and happens something strange. i login with the test user but the application never shows the buttons of “lemonade refill”, “drinking glass” and “daily dose”. I replace the products IDs but nothing happened.

Is this normal?
[import]uid: 105206 topic_id: 25314 reply_id: 102666[/import]

Hey, @nml, with InAppDemo, do print statements show? And if they do, how far does the code executes? I’ve never built InAppDemo myself, and I don’t recall if it had lots of print statements – but if it doesn’t, you might want to add them to key spots and see what kind of error messages you get (if any).

Naomi

Edit: By the way, I wonder if the device you’re using to test the IAP is jailbroken. Just in case you are not aware, IAP cannot be tested in the iTunes Connect Sandbox environment using jailbroken device… [import]uid: 67217 topic_id: 25314 reply_id: 102766[/import]

@nml - Remember to go test your IAP building your app using an Ad Hoc profile mate!

I think it is very important as only using one I finally GOT my IAP to work beautifully listening to Naomi generous tips! MAJOR THANKS FOR NAOMI! This girl is just AWESOME and EXPERT about IAP IMHO! :slight_smile: Hey Naomi, am very glad to get your helpful hand!

So, take note of everything that @Naomi has said and also remember of the Ad Hoc profile to test it.

PS: I have tested IAP using my *Team Provisioning Profile and that one will not let me test nothing! Always FAIL without any single ERROR message - just a popup telling FAIL nothing else.
So I wish you luck and am also here looking forward with you to get your IAP working nicely as well. :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 25314 reply_id: 102831[/import]

Hey, Rodrigo @RSCdev, so sweet of you with your kind words. Really, I’m no expert, though. It’s just that I struggled with IAP when I tackled it, spending very long frustrating hours, trying to troubleshoot what was so wrong with mine, thinking & trying every possible angles and options – honestly, I think I turned every possible stones along the way – and then, it turned out it was really about my provisioning profile & keychain issue in my case. But the net result of that struggle was, maybe, I can help others a little. :slight_smile:

So glad to hear you got yours working!

Naomi [import]uid: 67217 topic_id: 25314 reply_id: 102838[/import]

@Naomi,

Your patience and very detailed “tips” offered for me along the way and always “on-time” was the key for me to get my IAP working nice as it is now.

PS: You said you help “a little”? Haha, I say you help A LOT. :slight_smile:

Thank you so much is my word for you.
@nml Excuse me for stg. :slight_smile:

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 25314 reply_id: 102839[/import]

Hey Rodrigo, now that you mentioned “ad hoc” profiles i believe my problem lies within that area. Or maybe just one part of my problem, but surely i’m missing something there.
Thing is, i never really understood the difference between profiles, only needed to know that distribution profiles are for commercial distribution, and development profiles are, well… for development. But in particular the differences between development profiles where never clear to me. I currently use 3 different profiles (in fact, i only use 2 of them) which are 2 development profiles ( i don’t actually remember why i created 2) and a distribution profile.
How and what for should i use an ad hoc profile?

Thank you both!! [import]uid: 105206 topic_id: 25314 reply_id: 102881[/import]

@nml ,

Mate, if you say that are using the Development Profile SO I believe you FOUND your problem (at least the biggest for now).

Because I was like you trying to get the IAP to work using the Development Profile, Team Profile, etc etc etc…BUT since I got @Naomi & @Peach tips about the profile I did build one Ad-Hoc one and PUFF! All started working without that horribles messages of Failed. :slight_smile:

So, go this route too!

To build an Ad-Hoc profile is very easy just following this (by @Naomi also):
go to Apple dev center, sign in, go to Provisioning Portal, click on Provisioning, select Distribution, click on New Profile, choose AdHoc (not App Store), create profile name (such as MyGame AdHoc - so that you know this is AdHoc certificate of your specific app), select an App ID of the app and select devices you want to install the AdHoc version of your app. The rest works the same as installing App Store version of the distribution certificate.
PS: After all that I was also able to test the Sample of IAP made by Ansca just replacing the “productID” into the code by my own.

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 25314 reply_id: 102895[/import]

Hi again!

I tried doing an Ad Hoc profile.
I created one, downloaded and installed on the device. But the “failed” error still appears.

Tomorrow i’ll try with the print statements that @Naomi says.

One question, how do i know if the device is jailbroken?

Thank you both again. [import]uid: 105206 topic_id: 25314 reply_id: 102984[/import]

@nml, please, remember to be logged out of any iTunnes user before you try to make a purchase. Be sure to not have any logged user on the decive you`re testing it out because it would be a reason for you to see this “horrible fail message”.

So, as you have created a new “TEST USER account” do only use that for testing purposes and also the Ad-Hoc profile (being sure that youve "linked" your new Ad-Hoc profile for the "exact" AppID (the app) you want to get IAP working (sorry saying it, but just to make sure). Hey, do not get so much "bad" about the IAP, because honestly it can get you mad, but lets keep going on because I`ll be happy only when I see you cracking it out! LoL :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 25314 reply_id: 102988[/import]

@nml, about jailbroken device, I don’t know how to tell. The fastest way to find out might be to ask the owner of the device – I’m sure he/she would know if the device is jailbroken.

As Rodrigo said, the most important thing is not to give up. The hardest part is figuring out what’s not working. Once you identify the issue, it’s not so hard to find the solution.

Good luck!

Naomi [import]uid: 67217 topic_id: 25314 reply_id: 103001[/import]

Well. I follow all steps but the “failed” error continues.

I’ve linked the Ad Hoc profile for the app. I create a new test user and I logged out of itunes before run the app. I asked and the device is not jailbroken.

I tried with the print statements to. I discovered that my code executes until the beginning of transactionCallback, but doesn’t enter to any “if” and i think that doesn’t executes “store.finishTransaction( event.transaction )” neither.

About the InAppDemo, i tried it with my product ID but no one of the products buttons appeared. Why this happens? Only appears the “Restore” button.
[import]uid: 105206 topic_id: 25314 reply_id: 103059[/import]

I have no clue why InAppDemo isn’t working for you. As I mentioned earlier, I haven’t used it myself. Let’s hope someone familiar with the demo version will chime in…

By the way, which daily build are you using? I just checked 783, and it has a folder for InAppPurchase (not InAppDemo.) It may be irrelevant, but maybe you could try using the latest daily build and try the InAppPurchase that comes with it?

Naomi

P.S. If your code never make it to loadProductsCallback, there maybe something wrong with your certificate/profile. When I had the issue with my provisioning profile & keychain, I could not get my code to execute the loadProductsCallback… [import]uid: 67217 topic_id: 25314 reply_id: 103097[/import]