IOS - application purchase - price of products

In my iOS application, I have 3 products in which users can purchase a purchase through the application. From my iOS application, I just want to get the price of all three elements that are on the Apple server. How can I get only the price without user intervention. (Maybe I should handle it taking into account the load or some method)

+4
source share
5 answers

You do not need any user intervention to get product information. All you have to do is send information about the product request and implement a callback method that will process the response as shown below (the example was taken from http://troybrant.net/blog/2010/01/in-app- purchases-a-full-walkthrough / ):

- (void)requestProUpgradeProductData { NSSet *productIdentifiers = [NSSet setWithObject:@"com.runmonster.runmonsterfree.upgradetopro" ]; productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; productsRequest.delegate = self; [productsRequest start]; // we will release the request object in the delegate callback } #pragma mark - #pragma mark SKProductsRequestDelegate methods - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSArray *products = response.products; proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain] : nil; if (proUpgradeProduct) { NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle); NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription); NSLog(@"Product price: %@" , proUpgradeProduct.price); NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier); } for (NSString *invalidProductId in response.invalidProductIdentifiers) { NSLog(@"Invalid product id: %@" , invalidProductId); } // finally release the reqest we alloc/init'ed in requestProUpgradeProductData [productsRequest release]; [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil]; } 

Just call requestProUpgradeProductData from viewDidLoad.

+10
source

You can create an instance of SKProductsRequest with a list of known identifiers at any time. I did this when the application starts. This is an asynchronous call using a delegate, so it's easy to get around without blocking it.

 myProductsRequest = [SKProductsRequest initWithProductIdentifiers:someSetOfIds]; myProductsRequest.delegate = myDelegageSomewhere; 

In SKProductsRequestDelegate :

 - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { for(SKProduct *product in response.products) { [self doSomethingWithPrice:product.price] } } 

The information is tied to an iTunes user account. That is how he gets the price for different stores in the country (different currencies).

+5
source
 -(NSString*)getPrice:(SKProduct*)product{ NSNumberFormatter * _priceFormatter; _priceFormatter = [[NSNumberFormatter alloc] init]; [_priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; [_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [_priceFormatter setLocale:product.priceLocale]; return [_priceFormatter stringFromNumber:product.price]; } 
+2
source

Swift 3.x, you will use below

 public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) { for product in response.products { let price = product.price let currencySymbol = productpriceLocale.currencySymbol } } 
0
source

You can add this function to your class.

 func priceOf(product: SKProduct) -> String { let numberFormatter = NumberFormatter() numberFormatter.formatterBehavior = .behavior10_4 numberFormatter.numberStyle = .currency numberFormatter.locale = product.priceLocale return numberFormatter.string(from: product.price)! } 

Then you can give him your product!

 priceLabel.text = "The price of the item is \(priceOf(product: product))" 

Replace product name of your SKProduct.

0
source

Source: https://habr.com/ru/post/1383482/


All Articles