Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - In app purchase - Get products price

In my iOS application, I've 3 products where users can purchase using in-app purchase. From my iOS application, i just want to get the price of all the 3 items that are on the apple server. How can I get only the price without user's intervention. (May be i've to handle in view did load or some method)

like image 256
Satyam Avatar asked Nov 28 '11 18:11

Satyam


1 Answers

You don't need any user intervention to get any product info. All you have to do is to send a product request info and implement a callback method that'll handle the response as shown below (the example has been 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.

like image 56
Sanjay Chaudhry Avatar answered Sep 22 '22 13:09

Sanjay Chaudhry