In-app purchase price shown on screen (with currency)

I need buttons that you must use to buy something to show the price of this.

For example: "5 coins € 0.99"

But if I create UIlabel with this text, the Americans will also see the price in € instead of usd.

Now, how can I set the price in which it is set for the currency in which the user lives? I have seen this in some games, so I am convinced that this is possible.

Thank you!

+8
ios xcode swift itunesconnect in-app-purchase
source share
2 answers

If purchases are made through the Apple App Store (using the StoreKit infrastructure), you need to get the price + currency from the SKProduct object (prices will vary).

https://developer.apple.com/library/ios/documentation/StoreKit/Reference/SKProduct_Reference/

Update

  • You need to complete a request to download available products.
var productID:NSSet = NSSet(object: "product_id_on_itunes_connect"); var productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID); productsRequest.delegate = self; productsRequest.start(); 
  1. The delegate request will return SKProduct .
 func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) { println("got the request from Apple") var validProducts = response.products if !validProducts.isEmpty { var validProduct: SKProduct = response.products[0] as SKProduct if (validProduct.productIdentifier == self.product_id) { println(validProduct.localizedTitle) println(validProduct.localizedDescription) println(validProduct.price) buyProduct(validProduct); } else { println(validProduct.productIdentifier) } } else { println("nothing") } } 
  1. SKProduct contains all the necessary information to display the localized price, but I suggest creating the SKProduct category, which formats the price + currency for the current user locale
 import StoreKit extension SKProduct { func localizedPrice() -> String { let formatter = NSNumberFormatter() formatter.numberStyle = .CurrencyStyle formatter.locale = self.priceLocale return formatter.stringFromNumber(self.price)! } } 

Information obtained from here and here .

+16
source share

You might want to localize (internationalize) your interface and texts.

To do this, you will see how to do it:

  • Your storyboard (you will still process one, but translate the texts you want in the internal file)
  • Inside your code. Trough NSLocalizedString , for example: http://goo.gl/jwQ5Po (Apple), http://goo.gl/S1dCUW (NSHipster), ...
+2
source share

All Articles