Search code examples
iosin-app-purchasemkstorekit

Get local price for IAP using MKStoreKit


I am using MKStoreKit for IAP. I can get all the task done easily (it's simple and easy to use) but m stuck to get the local price by productid

Is it possible to get the local price in mkstorekit ?

And if i will display local price for product will it create any problem in review ?


Solution

  • //...
    self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers];
    self.productsRequest.delegate = self;
    [self.productsRequest start];
    //...
    
    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
        NSLog(@"Loaded list of products...");
        NSArray * skProducts = response.products;
        for (SKProduct *product in skProducts) {
           NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
           [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
           [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
           [numberFormatter setLocale:product.priceLocale];
           NSString *formattedPrice = [numberFormatter stringFromNumber:product.price];
           //Use formattedPrice
    
        }
    }
    

    EDIT

    If you are using: https://github.com/MugunthKumar/MKStoreKit

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSKProductsAvailableNotification:) name:kMKStoreKitProductsAvailableNotification object:nil];
    [[MKStoreKit sharedKit] startProductRequest];
    //...
    
    - (void)handleSKProductsAvailableNotification:(NSNotification *)note
    {
        NSArray * skProducts = [MKStoreKit sharedKit].availableProducts; 
        for (SKProduct *product in skProducts) {
           NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
           [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
           [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
           [numberFormatter setLocale:product.priceLocale];
           NSString *formattedPrice = [numberFormatter stringFromNumber:product.price];
           //Use formattedPrice
    
        }
    }