Objective c 使用SKProductsRequest请求应用程序内购买时订单错误
我已经在我的应用程序中实现了应用程序内购买,但在请求产品时遇到了一些问题。从商店返回的产品的顺序与我的标识符列表的顺序不匹配。 我要求提供具有以下代码的产品:Objective c 使用SKProductsRequest请求应用程序内购买时订单错误,objective-c,cocoa-touch,in-app-purchase,Objective C,Cocoa Touch,In App Purchase,我已经在我的应用程序中实现了应用程序内购买,但在请求产品时遇到了一些问题。从商店返回的产品的顺序与我的标识符列表的顺序不匹配。 我要求提供具有以下代码的产品: self.request = [[[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects: @"50Hints",@"120Hints",@"250Hints",@"400Hints", nil]] autorelease]; //NSL
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>"
)
产品(
"",
"",
"",
""
)
顺序不同(第一个对应于@“120提示”而不是@“50提示”)
这在IOS 5之前不是问题,因为我可以使用[SKPaymentPaymentWithProductIdentifier:productIdentifier],productIdentifier是对应于产品名称的字符串,但现在我必须使用paymentWithProduct,它接受产品(例如SKProduct:0xc660bb0),而不是名称。所以我必须找出哪个是哪个
有没有办法通过paymentWithProduct使用产品名称购买产品?如果不是,应用内购买的顺序是随机变化的还是永久性的
干杯,伙计们
Cyril我这样做的方式是使用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];
}