iOS ios_iap_IsAuthorisedForPayment not working?

D

dave_matthew

Guest
Hi all,

I'm currently developing a game for iOS and I'm running into some issues using the ios_iap_IsAuthorisedForPayment() function from the official Apple IAPs extension by YoYo Games.

I'm getting an error when calling the ios_iap_IsAuthorisedForPayment() function (see the code and error below). It's being called on the create event of a persistent object as the docs suggest.

I'm following the documentation on this page, and as far as I can see, my code is pretty much identical. I might be missing something super obvious, but has anybody else experienced an issue like this? If it helps, I'm currently using the GameMaker Studio 2.3 Beta, so this might be causing the issue.

If anybody needs more info let me know. Thanks in advance.

GML:
global.restore_purchases = false;
global.IAP_Enabled = ios_iap_IsAuthorisedForPayment();
global.ProductID[0, 0] = "product_king_hat";
global.ProductID[1, 0] = "product_knight_hat";
global.ProductID[2, 0] = "product_wizard_hat";
global.ProductID[3, 0] = "product_cowboy_hat";
global.ProductID[4, 0] = "product_gentlecow_hat";
global.ProductID[5, 0] = "product_diver_hat";
global.ProductID[6, 0] = "product_doctor_hat";
global.ProductID[7, 0] = "product_udder_hat";
global.ProductID[8, 0] = "product_cap_hat";
global.ProductID[9, 0] = "product_firecow_hat";
global.ProductID[10, 0] = "product_policecow_hat";
global.ProductID[11, 0] = "product_pirate_hat";
global.ProductID[12, 0] = "product_leprechaun_hat";
global.ProductID[13, 0] = "product_catears_hat";
global.ProductID[14, 0] = "product_heli_hat";

if (global.IAP_Enabled) {
    for (var i = 0; i <= 14; i++) {
        ios_iap_AddProduct(global.ProductID[i, 0]);
    }
    ios_iap_QueryProducts();
    
    var _json = ios_iap_QueryPurchases();
    if (_json != "") {
        var _map = json_decode(_json);
        var _plist = _map[? "purchases"];
        var _sz = ds_list_size(_plist);
    
        // loop through purchases
        for (var i = 0; i < _sz; ++i;) {
            var _pmap = _plist[| i];
            var _ptoken = _pmap[? "purchaseToken"];
        
            // Check purchases
            if _pmap[? "purchaseState"] != ios_purchase_failed {
                var _receipt = ios_iap_GetReceipt();
                if ios_iap_ValidateReceipt() == true {
                    var _num = 0;
                    while(_pmap[? "productId"] != global.ProductID[_num, 0]) {
                        ++_num;
                    }
                    switch (_num) {
                        case 0: unlock_purchased_hat("King"); break;
                        case 1: unlock_purchased_hat("Knight"); break;
                        case 2: unlock_purchased_hat("Wizard"); break;
                        case 3: unlock_purchased_hat("Cowboy"); break;
                        case 4: unlock_purchased_hat("Gentlecow"); break;
                        case 5: unlock_purchased_hat("Diver"); break;
                        case 6: unlock_purchased_hat("Doctor"); break;
                        case 7: unlock_purchased_hat("Udder Hat"); break;
                        case 8: unlock_purchased_hat("Cap"); break;
                        case 9: unlock_purchased_hat("Firecow"); break;
                        case 10: unlock_purchased_hat("Policecow"); break;
                        case 11: unlock_purchased_hat("Pirate"); break;
                        case 12: unlock_purchased_hat("Leprechaun"); break;
                        case 13: unlock_purchased_hat("Cat Ears"); break;
                        case 14: unlock_purchased_hat("Heli-hat"); break;
                    }
                }
                else {
                    // Validation failed, so deal with it here
                    // You will still need to finalise the transaction
                    show_message_async("Transaction failed! Please check your internet connection, and try again.");
                }
            }
            else {
                // Purchase failed, so deal with it here
                // You will still need to finalise the transaction
                show_message_async("Transaction failed! Please check your internet connection, and try again.");
            }
            
            ios_iap_FinishTransaction(_ptoken);
            ds_map_destroy(_pmap);
        }
        ds_map_destroy(_map);
    }
}
___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object obj_IAP:

Variable <unknown_object>.ios_iap_IsAuthorisedForPayment(100427, -2147483648) not set before reading it.
at gml_Object_obj_IAP_Create_0 (line 7) - global.IAP_Enabled = ios_iap_IsAuthorisedForPayment();
############################################################################################
gml_Object_obj_IAP_Create_0 (line 7)
 
Top