Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Get Local Currency Symbol — Gideros Forum

Get Local Currency Symbol

emreemre Member
edited December 2013 in General questions
Hii,
Is there a way to get local currency string?
On storekit Event.REQUEST_PRODUCTS_COMPLETE event we can get "price". But I needed to show with local currency like
0.99$

Thanks.

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited December 2013 Accepted Answer
    @emre unfortunately it seems that SKProduct does not contain the currency either.
    All it does, is, it returns the locale of the price.

    But what you could do, is to get a formatted string from the price, like this:
    inside storekit.mm
    in this function
    static void dispatchEvent
    find
    	if (products)
    	{
    		lua_newtable(L);
    		for(int i = 0; i < [products count]; ++i)
    		{
    			SKProduct* product = [products objectAtIndex:i];
     
    			lua_newtable(L);
     
    			lua_pushstring(L, [product.localizedTitle UTF8String]);
    			lua_setfield(L, -2, "title");
     
    			lua_pushstring(L, [product.localizedDescription UTF8String]);
    			lua_setfield(L, -2, "description");
     
    			lua_pushnumber(L, [product.price doubleValue]);
    			lua_setfield(L, -2, "price");
     
    			lua_pushstring(L, [product.productIdentifier UTF8String]);
    			lua_setfield(L, -2, "productIdentifier");
     
    			lua_rawseti(L, -2, i + 1);
    		}
    		lua_setfield(L, -2, "products");
    	}
    And modify it to:
    	if (products)
    	{
    		lua_newtable(L);
    		for(int i = 0; i < [products count]; ++i)
    		{
    			SKProduct* product = [products objectAtIndex:i];
     
    			lua_newtable(L);
     
    			lua_pushstring(L, [product.localizedTitle UTF8String]);
    			lua_setfield(L, -2, "title");
     
    			lua_pushstring(L, [product.localizedDescription UTF8String]);
    			lua_setfield(L, -2, "description");
     
    			NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    			[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    			[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    			[numberFormatter setLocale:product.priceLocale];
    			NSString *formattedString = [numberFormatter stringFromNumber:product.price];
    			lua_pushstring(L, formattedString);
    			lua_setfield(L, -2, "price");
     
    			lua_pushstring(L, [product.productIdentifier UTF8String]);
    			lua_setfield(L, -2, "productIdentifier");
     
    			lua_rawseti(L, -2, i + 1);
    		}
    		lua_setfield(L, -2, "products");
    	}
  • emreemre Member
    edited December 2013
    Hi Arturs,
    After modification, "price" value now will be like "0.99$" ?
    And do you have chance to test the code?
    Thanks for quick reply.
  • Hi Arturs,
    On line:
    lua_pushstring(L, formattedString);
    I get the error:
    No matching function for call to 'lua_pushstring'

    Thanks.
  • @emre sorry, I'm on holidays so away form my Mac, no chance to test, but yes you are right, that line should be:
    lua_pushstring(L, [formattedString UTF8String]);
  • Thanks Arturs It is working now. Tested.
  • totebototebo Member
    edited July 2014
    Did this ever get implemented for Gamekit for iOS? If so, what's the LUA code to grab currency symbol an item?
    My Gideros games: www.totebo.com
  • totebototebo Member
    I'll answer myself; it's implemented! This code:
    IAB:requestProducts()
    Spits this data back:
    	[products]	table
    	[products]	[1]	table
    	[products]	[1]	[price]	string	£0.69
    	[products]	[1]	[description]	string	Product 1
    	[products]	[1]	[title]	string	Pay to Win
    	[products]	[1]	[productId]	string	p1
    It seems the "price" string contains the whole shebang. Handy.

    Niclas
    My Gideros games: www.totebo.com
Sign In or Register to comment.