Wrong order when requesting in app purchases using SKProductsRequest

I have managed to implement in-app purchases in my app but I am having some problems when requesting the products. The order of the products returned from the store do not match the order of my list of identifiers. I am requesting the products with the following code :

self.request = [[[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects: @"50Hints",@"120Hints",@"250Hints",@"400Hints", nil]] autorelease];
    //NSLog(@"Sending request...");
    request.delegate = self;
    [request start];

and I am receiving the list of products as:

the products (
    "<SKProduct: 0xc660bb0>",
    "<SKProduct: 0xc661110>",
    "<SKProduct: 0xc661160>",
    "<SKProduct: 0xc6611b0>"
)

which is not in the same order (The first one corresponds to @"120Hints" instead of @"50Hints")

That wasn't a problem before IOS 5 because I could use [SKPayment paymentWithProductIdentifier:productIdentifier], productIdentifier being the string corresponding to the name of the product but now I have to use paymentWithProduct which accept a product (e.g SKProduct: 0xc660bb0) and not the name. So I have to find out which is which.

Is there a way to buy the product using its name by using paymentWithProduct ? If not, is the order of the in app purchases going to change randomely or is it permanent ?

Cheers guys Cyril

Answers


The way I've done this is to use the properties of the SKProduct, some of which I display in a table for the user to choose from -- one of the columns has the product identifier displayed. This was done for a OSX project, but the concept should be the same.

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    self.productsFromItunes = [NSMutableArray array];
    for(SKProduct *aProduct in response.products){
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:aProduct,@"theProduct",aProduct.price,@"thePrice",aProduct.localizedTitle,@"theTitle",aProduct.productIdentifier,@"theID",nil];
        [self.productsFromItunes addObject:dict];
    }
    [NSBundle loadNibNamed:@"BuyCredits" owner:self];
    [self.buyCreditsWindow makeKeyAndOrderFront:self];// this window has the table of choices
}

// Connected to the "Purchase" and "Cancel" buttons in the Buy Credits window
-(IBAction)buyOrCancel:(NSButton *)sender {
    if ([sender.title isEqualToString:@"Purchase"]){
        SKProduct *chosenProduct = [self.buyCreditsController.selectedObjects.lastObject valueForKey:@"theProduct"];
        SKPayment *thePayment = [SKPayment paymentWithProduct:chosenProduct];
        [SKPaymentQueue.defaultQueue addPayment:thePayment]; // This method sends the buy request to the app store
    }
    [self.buyCreditsWindow orderOut:self];
}

Need Your Help

Cells in UITableView keep clear when searching in UISearchBar

ios objective-c uitableview uisearchbar uisearchdisplaycontroller

I have got an application which has a UITableView containing two sections. Now I wanted to add a UISearchBar to allow searching. And the searching really works pretty fine and selects the correct c...

Adding annotations to a PlotChart

flex charts

I'm looking to add(and remove, dynamically) text annotations to the PlotChart. Specifically I want to annotate plot points in the chart. I'm currently using the CircleItemRenderer for the points....