StoreKit not working on tvOS

You might want to consider delaying the loadProducts call. If .init() isn’t done initing and you call loadProducts too soon, it won’t be ready. Most networking type things are called asynchronous which means we start the process in the background and return to your app immediately so you app doesn’t pause waiting on a slow network connection.

I can’t speak for how much work Scott’s plugin does during the init phase, but you can either load the products on a timer of a second or two. I doubt your users are going to be hitting the buy button within the first few seconds of the app starting. Or if the .init() call calls it’s on call back function to say it’s done initializing, then you could use that as your indicator that the system is ready to go and then call loadProducts() from that listener.  I would even wrap that call in a short timer (say 10ms) to make sure that listener function has time to exit before it gets called again by some other API call.

Rob

@scott, when I change publisherID I get an error message when trying to build.


A device build error occurred on the server. 

 

Error: You are not subscribed to the following plugin:

 

Plugin: plugin.storeKit

Publisher: tech.scotth

 


The plugin is activated and paid since dec 13, 2016.

That’s odd

my bad, I was assuming changing the publisher id in metadata.json affect the marketplace hosting publisher id. I would continue to use the com.scottrules44 until everything is sorted out.

Just tested in sand box, 

Used the following code(used timer because i am not good with joysticks

local store = require("plugin.storeKit") local json = require("json") store.init(function(e) print( "init") print( "------" ) print(json.encode(e) ) print( "------" ) if e.transaction.state == "purchased" then native.showAlert("storeKit", "the purchase worked", {"ok"}) end end) local Products = {"com.anscamobile.NewExampleInAppPurchase.NonConsumableTier1", "com.anscamobile.NewExampleInAppPurchase.ConsumableTier1"} local thePurchaseProduct = "com.anscamobile.NewExampleInAppPurchase.ConsumableTier1" timer.performWithDelay( 1000, function ( ) store.loadProducts( Products, function ( e ) print( "loadProducts") print( "------" ) print(json.encode(e) ) print( "------" ) timer.performWithDelay( 3000, function ( ... ) store.purchase(thePurchaseProduct) end) native.showAlert("storeKit", "products loaded", {"ok"}) end ) end)

Got the following out:(noted i cutted out unimportant things)

 [Device] loadProducts Jan 08 02:01:07.269 [Device] ------ Jan 08 02:01:07.270 [Device] {"products":[{"title":"ConsumableTier1","productIdentifier":"com.anscamobile.NewExampleInAppPurchase.ConsumableTier1","localizedPrice":3.99,"price":3.99,"description":"cool ConsumableTier1"},{"title":"NonConsumableTier1","productIdentifier":"com.anscamobile.NewExampleInAppPurchase.NonConsumableTier1","localizedPrice":1.99,"price":1.99,"description":"cool NonConsumableTier1"}],"name":"productList","invalidProducts":[]} [Device] ------ Jan 08 02:03:28.099 [Device] init Jan 08 02:03:28.108 [Device] ------ Jan 08 02:03:28.108 [Device] {"transaction":{"state":"purchased","originalReceipt":"{\134"status\134":0, \134"environment\134":\134"Sandbox\134", \134n\134"receipt\134":{\134"receipt\_type\134":\134"ProductionSandbox\134", \134"adam\_id\134":0, \134"app\_item\_id\134":0, \134"bundle\_id\134":\134"com.scotthinc.com\134", \134"application\_version\134":\134"2017.01.081400\134", \134"download\_id\134":0, \134"version\_external\_identifier\134":0, \134"receipt\_creation\_date\134":\134"2017-01-08 20:03:26 Etc/GMT\134", \134"receipt\_creation\_date\_ms\134":\134"1483905806000\134", \134"receipt\_creation\_date\_pst\134":\134"2017-01-08 12:03:26 America/Los\_Angeles\134", \134"request\_date\134":\134"2017-01-08 20:03:28 Etc/GMT\134", \134"request\_date\_ms\134":\134"1483905808471\134", \134"request\_date\_pst\134":\134"2017-01-08 12:03:28 America/Los\_Angeles\134", \134"original\_purchase\_date\134":\134"2013-08-01 07:00:00 Etc/GMT\134", \134"original\_purchase\_date\_ms\134":\134"1375340400000\134", \134"original\_purchase\_date\_pst\134":\134"2013-08-01 00:00:00 America/Los\_Angeles\134", \134"original\_application\_version\134":\134"1.0\134", \134n\134"in\_app\134":[\134n{\134"quantity\134":\134"1\134", \134"product\_id\134":\134"thePack3\134", \134"transaction\_id\134":\134"1000000244365152\134", \134"original\_transaction\_id\134":\134

My tv is showing an alert that says “title” storeKit “the purchase worked” (with ok button), I just (jan/7 1:58) tested this using the latest every thing( stable build , Xcode, and tvOS os) also I am using the real account(just type my long apple password into the tv, fun :wink:

I am going to test audio

Testing with lasted stable build audio is continues play

also test with daily builds CoronaSDK 2016.3012 

just added 

local someLoopingMusic = audio.loadStream( "sampleMusic.mp3" ) local someLoopingMusicChannel = audio.play( someLoopingMusic, { channel=1, loops=-1 } )

to the sample above. audio and events seem fine

proof:

https://www.dropbox.com/s/c8ooptdtedntb6n/Video%20Jan%2008%2C%202%2017%2049%20PM.mov?dl=0

Please make sure your products are loaded before you purchase.

From docs https://scotth.tech/plugin-storeKit :

Gotchas: You must .loadProducts before restoring or buying 

Also make sure info is setup correctly in iTunes connect

Thanks

Scott

I’m trying the following code

timer.performWithDelay( 1500, function () store.loadProducts( Products, function ( e ) print( "loadProducts") print( "------" ) print(json.prettify(e) ) print( "------" ) -- --native.showAlert("Store", "Products loaded", {"OK"}) if e.invalidProducts then --native.showAlert("Error", "Didn't find any products", {"OK"}) -- No products availble --ProductPrice = "$2.99" else native.showAlert("Store", "Products loaded", {"OK"}) ProductPrice = e.products.localizedPrice or "$2.99" print(" price locale: "..e.products.localizedPrice) productsLoaded = true end end ) end) 

Still get the following out:

[Device] loadProducts [Device] ------ [Device] { [Device] ------

hmm it looks like it’s working now. I just changed

print(json.prettify(e) )

to

print(json.encode(e) )

then I recieved the product list.

But I can’t get store.restore() to work. Right now I just re-use the purchase option when one want to restore. I will try to upload to appstore again. Thanks for your help so far.

can you show me how you are using restore?

After store.init() and store.loadProducts()

I’m using:

store.restore()

but never reach store init function as it looks

 local store = require("plugin.storeKit") local json = require("json") store.init(function(e) print( "init") print( "------" ) print(json.encode(e) ) print( "------" ) if e.transaction.state == "purchased" then native.showAlert("Success", "Thank you for the purchase", {"OK"}) removeLocking() elseif e.transaction.state == "restored" then native.showAlert("Success", "Your product is restored!", {"OK"}) removeLocking() elseif e.transaction.state == "failed" then native.setActivityIndicator( false ) native.showAlert("Failed", "Your purchase failed. Please, try again.", {"OK"}) else native.setActivityIndicator( false ) end end)

store.loadProducts()

timer.performWithDelay( 1000, function ( ) store.loadProducts( Products, function ( e ) print( "loadProducts") print( "------" ) print(json.encode(e) ) print( "------" ) --[[] timer.performWithDelay( 3000, function ( ... ) store.purchase(ProductToPurchase) end) native.showAlert("storeKit", "products loaded", {"ok"}) --]] end ) --]] end)
2017-01-08 18:32:18.779683 App[305:130278] restore 2017-01-08 18:32:19.421180 App[305:130278] init 2017-01-08 18:32:19.421403 App[305:130278] ------ 2017-01-08 18:32:19.424043 App[305:130278] {"state":"restored","transaction":[{"productIdentifier":"thePack3","date":"00:32 2017/Jan/9","originalReceipt":"{\"status\":0, \"environment\":\"Sandbox\", \n\"receipt\":{\"receipt\_type\":\"ProductionSandbox\", \"adam\_id\":0, \"app\_item\_id\":0, \"bundle\_id\":\"com.scotthinc.com\", \"application\_version\":\"1\", \"download\_id\":0, \"version\_external\_identifier\":0, \"receipt\_creation\_date\":\"2017-01-09 00:32:19 Etc/GMT\", \"receipt\_creation\_date\_ms\":\"1483921939000\", \"receipt\_creation\_date\_pst\":\"2017-01-08 16:32:19 America/Los\_Angeles\", \"request\_date\":\"2017-01-09 00:32:19 Etc/GMT\", \"request\_date\_ms\":\"1483921939368\", \"request\_date\_pst\":\"2017-01-08 16:32:19 America/Los\_Angeles\", \"original\_purchase\_date\":\"2013-08-01 07:00:00 Etc/GMT\", \"original\_purchase\_date\_ms\":\"1375340400000\", \"original\_purchase\_date\_pst\":\"2013-08-01 00:00:00 America/Los\_Angeles\", \"original\_application\_version\":\"1.0\", \n\"in\_app\":[\n{\"quantity\":\"1\", \"product\_id\":\"thePack3\", \"transaction\_id\":\"1000000244365152\", \"original\_transaction\_id\":\"1000000244365152\", \"purchase\_date\":\"2016-10-21 06:08:37 Etc/GMT\", \"purchase\_date\_ms\":\"1477030117000\", \"purchase\_date\_pst\":\"2016-10-20 23:08:37 America/Los\_Angeles\", \"original\_purchase\_date\":\"2016-10-21 06:08:37 Etc/GMT\", \"original\_purchase\_date\_ms\":\"1477030117000\", \"original\_purchase\_date\_pst\":\"2016-10-20 23:08:37 America/Los\_Angeles\", \"is\_trial\_period\":\"false\"}, \n{\"quantity\":\"1\", \"product\_id\":\"com.anscamobile.NewExampleInAppPurchase.SubscriptionTier2\", \"transaction\_id\":\"1000000244700036\", \"original\_transaction\_id\":\"1000000244700036\", \"purchase\_date\":\"2016-10-23 05:39:59 Etc/GMT\", \"purchase\_date\_ms\":\"1477201199000\", \"purchase\_date\_pst\":\"2016-10-22 22:39:59 America/Los\_Angeles\", \"original\_purchase\_date\":\"2016-10-23 05:39:59 Etc/GMT\", \"original\_purchase\_date\_ms\":\"1477201199000\", \"original\_purchase\_date\_pst\":\"2016-10-22 22:39:59 America/Los\_Angeles\", \"is\_trial\_period\":\"false\"}, \n{\"quantity\":\"1\", \"product\_id\":\"com.anscamobile.NewExampleInAppPurchase.SubscriptionTier2\", \"transaction\_id\":\"1000000244966896\", \"original\_transaction\_id\":\"1000000244966896\", \"purchase\_date\":\"2016-10-24 17:27:16 Etc/GMT\", \"purchase\_date\_ms\":\"1477330036000\", \"purchase\_date\_pst\":\"2016-10-24 10:27:16 America/Los\_Angeles\", \"original\_purchase\_date\":\"2016-10-24 17:27:16 Etc/GMT\", \"original\_purchase\_date\_ms\":\"1477330036000\", \"original\_purchase\_date\_pst\":\"2016-10-24 10:27:16 America/Los\_Angeles\", \"is\_trial\_period\":\"false\"}, \n{\"quantity\":\"1\", \"product\_id\":\"com.anscamobile.NewExampleInAppPurchase.SubscriptionTier2\", \"transaction\_id\":\"1000000244967360\", \"original\_transaction\_id\":\"1000000244967360\", \"purchase\_date\":\"2016-10-24 17:28:18 Etc/GMT\", \"purchase\_date\_ms\":\"1477330098000\", \"purchase\_date\_pst\":\"2016-10-24 10:28:18 America/Los\_Angeles\", \"original\_purchase\_date\":\"2016-10-24 17:28:18 Etc/GMT\", \"original\_purchase\_date\_ms\":\"1477330098000\", \"original\_purchase\_date\_pst\":\"2016-10-24 10:28:18 America/Los\_Angeles\", \"is\_trial\_period\":\"false\"}, \n{\"quantity\":\"1\", \"product\_id\":\"com.anscamobile.NewExampleInAppPurchase.SubscriptionTier2\", \"transaction\_id\":\"1000000244967439\", \"original\_transaction\_id\":\"1000000244967439\", \"purchase\_date\":\"2016-10-24 17:29:32 Etc/GMT\", \"purchase\_date\_ms\":\"1477330172000\", \"purchase\_date\_pst\":\"2016-10-24 10:29:32 America/Los\_Angeles\", \"original\_purchase\_date\":\"2016-10-24 17:29:32 Etc/GMT\", \"original\_purchase\_date\_ms\":\"1477330172000\", \"original\_purchase\_date\_pst\":\"2016-10-24 10:29:32 America/Los\_Angeles\", \"is\_trial\_period\":\"false\"}, \n{\"quantity\":\"1\", \"product\_id\":\"com.anscamobile.NewExampleInAppPurchase.NonConsumableTier1\", \"transaction\_id\":\"1000000244699775\", \"original\_transaction\_id\":\"1000000244699775\", \"purchase\_date\":\"2016-10-23 05:26:23 Etc/GMT\", \"purchase\_date\_ms\":\"1477200383000\", \"purchase\_date\_pst\":\"2016-10-22 22:26:23 America/Los\_Angeles\", \"original\_purchase\_date\":\"2016-10-23 05:26:23 Etc/GMT\", \"original\_purchase\_date\_ms\":\"1477200383000\", \"original\_purchase\_date\_pst\":\"2016-10-22 22:26:23 America/Los\_Angeles\", \"is\_trial\_period\":\"false\"}]}}","packageName":"com.scotthinc.com"}],"name":"storeTransaction"} 2017-01-08 18:32:19.425202 App[305:130278] ------

restore seems to happen for me

modded code before to this

store.init(function(e) print( "init") print( "------" ) print(json.encode(e) ) print( "------" ) if e.transaction.state == "purchased" then print( "restore") store.restore() end end)

that may be my fault

e.state == “restored”

will fix it

pushed out and update (will take up to an hour to) that should fix 

e.transaction.state == “restored”

please note publisher id has changed from “com.scottrules44” to “tech.scotth”

https://forums.coronalabs.com/topic/67229-buildsettings-publisher-id-change-soon-for-comscottrules44/?p=348072

Scott, when I change to the new publisherID I get this when trying to upload to appstore. 

Package Summary: 1 package(s) were not uploaded because they had problems: /var/folders/90/ws67dmw52y7gw4xksq1pgj\_h0000gn/T/0B240973-D80B-4712-8B25-04C0EF98DE4A/1131252020.itmsp - Error Messages: ERROR ITMS-90087: "Unsupported Architectures. The executable for Deep Ocean Aquarium.app/Frameworks/Corona\_plugin\_storeKit.framework contains unsupported architectures '[x86\_64]'." ERROR ITMS-90635: "Invalid Mach-O Format. The Mach-O in bundle "Deep Ocean Aquarium.app/Frameworks/Corona\_plugin\_storeKit.framework" isn’t consistent with the Mach-O in the main bundle. The main bundle Mach-O contains arm64(bitcode and machine code), while the nested bundle Mach-O contains X86\_64ALL(machine code). Verify that all of the targets for a platform have a consistent value for the ENABLE\_BITCODE build setting." ERROR ITMS-90209: "Invalid Segment Alignment. The app binary at 'Deep Ocean Aquarium.app/Frameworks/Corona\_plugin\_storeKit.framework/Corona\_plugin\_storeKit' does not have proper segment alignment. Try rebuilding the app with the latest Xcode version." ERROR ITMS-90125: "The binary is invalid. The encryption info in the LC\_ENCRYPTION\_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple's linker."

Looking into it

should be fixed(please try again in an hour)

Now it looks like everything except restore() works.

Can’t get store.restore() to work. It never returns to the init callback and I have to kill the app and restart inorder to use the app again.