Apple应用程序内购买 [英] Apple In-App Purchase

查看:104
本文介绍了Apple应用程序内购买的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设备的SANDBOX环境中测试In-App-Purchase时,我记录了以下错误:

While testing In-App-Purchase in the SANDBOX ENVIRONMENT on the device, I'm logging the following error :

错误域= SKErrorDomain Code = 0无法连接到iTunes StoreUserInfo = 0x2916a0 {NSLocalizedDescription =无法连接到iTunes Store} .t

我能够检索产品ID我通过iTunes Connect注册的。我在桌面视图中显示与这些产品相关的数据以及购买选项。
当我尝试购买产品时,会启动一项交易,但它并未要求我提供任何测试用户详细信息。我得到了上面提到的错误。

I'm able to retreive the product id's which i registered through iTunes Connect. I'm displaying data related with these products as in a table view along with Buying option. When i try to buy a product a transaction is initiated but it doesn't ask me for any test user details & i get the error as mentioned above.

我提供的是我实施的代码。

I'm providing the code which I implemented.

    //the below code is for RETREIVING THE PRODUCT id's

#pragma mark Store kit
-(IBAction)sendProductInfoRequest{
NSLog(@"sendProductInfoRequest");

NSSet *identifiersSet=[NSSet setWithObjects:[NSString stringWithFormat:@"%@",@".15April2011"],[NSString                          stringWithFormat:@"%@",@"15April201102"],nil];
SKProductsRequest *productRequest=[[SKProductsRequest alloc] initWithProductIdentifiers:identifiersSet];
productRequest.delegate=self;
[productRequest start];
NSLog(@"completing sendProductInfoRequest");
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSLog(@"yoooo!");
NSLog(@"The product request didReceiveResponse :%@",[response description]);
NSLog(@"The products are :%@",[response.products description]);

NSLog(@"The invalidProductIdentifiers are:%@",[response.invalidProductIdentifiers description]);

NSArray *products=response.products;



for(SKProduct *currentProduct in products){

NSLog(@"THE Product price is :%@",currentProduct.price);
NSLog(@"THE Product description is :%@",currentProduct.localizedDescription);
NSLog(@"THE Product title is :%@",currentProduct.localizedTitle);
NSLog(@"THE Product's product identifier is :%@",currentProduct.productIdentifier);

}

}



/the BuyProducts method is called when user clicks buy button related to a particular product
-(IBAction)BuyProducts
{
if ([SKPaymentQueue canMakePayments])
{
[self makePaymentRequestForThisProduct:isbnText.text];
}

}



-(void)makePaymentRequestForThisProduct:(NSString*)productID

{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:productID];  
[[SKPaymentQueue defaultQueue] addPayment:payment];
}



/I have added the transaction observer in applicationDidFinishLaunching method of AppDelegate
//Transaction Observer is a class

TransactionObserver *observer;
observer = [[TransactionObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];

//the TransactionObserver.m class

@implementation TransactionObserver


- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {

switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
NSLog(@"failed transaction");
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            default:
                break;
        }
    }
}

- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
NSLog(@"successful purchase");
  //  [self recordTransaction: transaction];
//[self provideContent: transaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
NSLog(@"restored incomplete transaction");
//   [self recordTransaction: transaction];
//   [self provideContent: transaction.originalTransaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) failedTransaction: (SKPaymentTransaction *)transaction
{

NSLog(@"The error description is:%@",[transaction.error description]);
if (transaction.error.code != SKErrorPaymentCancelled)
    {
if(transaction.error.code == SKErrorUnknown) {
NSLog(@"Unknown Error (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
  delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];

[failureAlert show];
[failureAlert release];
}

if(transaction.error.code == SKErrorClientInvalid) {
NSLog(@"Client invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
  delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}

if(transaction.error.code == SKErrorPaymentInvalid) {
NSLog(@"Payment invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
  delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}

if(transaction.error.code == SKErrorPaymentNotAllowed) {
NSLog(@"Payment not allowed (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
  delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
    }
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}


@end


推荐答案

这可能很荒谬,但是 - 如果您确定您的代码是正确的 - 请对iPod进行硬重置(完全擦除)(设置=>常规=>重置=>全部删除)内容和设置)。

This may be ridiculous, but -- if you're certain your code is correct -- do a hard reset (full wipe) of your iPod (Settings => General => Reset => Erase All Content and Settings).

这篇关于Apple应用程序内购买的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆