这是代码:
-(IBAction)purchase5010:(id)sender{
productUserRequests = 0;
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.mobice.wtm.5010"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
SKProduct *validProduct = nil;
int count = [response.products count];
if (count > 0) {
validProduct = [response.products objectAtIndex:productUserRequests];
}else if(!validProduct){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No products available at this time."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[self dismissModalViewControllerAnimated:YES];
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
SKProduct *validProduct = nil;
int count = [response.products count];
if (count > 0) {
validProduct = [response.products objectAtIndex:productUserRequests];
}else if(!validProduct){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No products available at this time."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[self dismissModalViewControllerAnimated:YES];
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
if (productUserRequests == 0) {
NSString *hints = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Hints"]];
int hintValue = [hints intValue];
hintValue+=50;
[hints release];
hints = [[NSString alloc]initWithFormat:@"%i", hintValue];
[hints writeToFile:[self pathOfFile:@"Hints"] atomically:YES];
NSString *reveals = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Reveals"]];
int revealValue = [reveals intValue];
revealValue+=50;
[reveals release];
reveals = [[NSString alloc]initWithFormat:@"%i", revealValue];
[reveals writeToFile:[self pathOfFile:@"Reveals"] atomically:YES];
}else if(productUserRequests == 1){
NSString *hints = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Hints"]];
int hintValue = [hints intValue];
hintValue+=150;
[hints release];
hints = [[NSString alloc]initWithFormat:@"%i", hintValue];
[hints writeToFile:[self pathOfFile:@"Hints"] atomically:YES];
NSString *reveals = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Reveals"]];
int revealValue = [reveals intValue];
revealValue+=20;
[reveals release];
reveals = [[NSString alloc]initWithFormat:@"%i", revealValue];
[reveals writeToFile:[self pathOfFile:@"Reveals"] atomically:YES];
}
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"In-app purchase failed. No money was charged."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
}
}
}
现在,每当我尝试购买该商品时,它都会显示“目前没有商品可用。”以及“应用内购买失败。没有收费。” 我想知道,上面的代码有什么问题吗?或者更有可能是itunes连接问题?
答案 0 :(得分:0)
而不是请求的完整包ID:@"com.mobice.wtm.5010"
,请继续只提供@"5010"
。
例如,我有一个产品com.example.somerandomapp.track01
,以下代码可以使用:
SKPayment *paymentRequest = [SKPayment paymentWithProductIdentifier: @"track01"];
有很多不同的因素可能会导致错误,这是一个很好的导致失败的清单here