2012-07-18 77 views
1

我已經設法在應用程序中實現應用程序內購買,但在請求產品時遇到了一些問題。從商店返回的產品訂單與我的標識符列表的順序不匹配。 我要求的產品,下面的代碼:使用SKProductsRequest在應用程序購買中請求錯誤的訂單

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

和我收到的產品清單如下:

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

這是不以相同的順序(第一個對應於@」 120Hints「而不是@」50Hints「)

這不是IOS 5之前的問題,因爲我可以使用[SKPayment paymentWithProductIdentifier:productIdentifier],productIdentifier是對應於產品名稱的字符串,但現在我必須使用paymentW ith產品接受產品(例如SKProduct:0xc660bb0)而不是名稱。所以我必須找出哪個是哪個。

有沒有辦法使用paymentWithProduct使用其名稱購買產品?如果沒有,應用內購買的順序是否會隨機更改或永久保存?

乾杯傢伙 西里爾

回答

0

我這樣做的方式是使用SKProduct的屬性,其中一些我在表中顯示爲用戶從選擇 - 其中一列有產品標識顯示。這是爲OSX項目完成的,但概念應該是相同的。

- (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]; 
} 
+0

完美。謝謝 – 2012-07-23 01:20:58

相關問題