苹果在应用程序内购买

问题描述:

虽然测试应用内购买在设备上的沙箱环境,我记录了以下错误:苹果在应用程序内购买

错误域= SKErrorDomain代码= 0“无法连接到iTunes商店” UserInfo = 0x2916a0 {NSLocalizedDescription =无法连接到iTunes Store} .t

我能够通过iTunes Connect注册产品ID。我在表格视图中显示与这些产品相关的数据以及购买选项。 当我尝试购买产品时发起了交易,但它并不要求我提供任何测试用户详细信息&我收到上述错误。

我提供了我实现的代码。

//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 
+3

您没有互联网连接? – 2011-05-03 16:49:47

+0

@richard我收到我在iTunes连接中为我的应用程序注册的所有产品的产品信息。这意味着我的Wi-Fi连接处于活动状态 – 2011-05-03 16:57:39

+0

对于恢复旧问题感到抱歉,但我现在遇到完全相同的问题,您是否可以找到除硬重置以外的其他任何解决方案? – 2012-06-08 19:49:24

这可能是可笑的,但是 - 如果你肯定你的代码是正确的 - 做硬重置您的iPod(设置(全抹)=>常规=>重置=>抹掉所有内容和“设置”)。

+0

有没有可能沙箱服务器停机?你不认为我在这里附上的代码是正确的吗? – 2011-05-04 10:14:51

+0

你在这里给出的答案是部分正确的。 – 2011-05-05 16:42:02

如果您使用其他iTunes帐户登录,也会发生这种情况。要测试在沙箱中的应用程序内购买,您需要从设置中的任何其他帐户注销。然后启动你的应用程序和做应用程序购买。当您的帐户被要求输入您创建的iTunes测试帐户。这样你的沙盒环境就可以完美工作。希望这会有所帮助。

也许沙盒服务器已关闭。

我能够获得的产品信息,但要求购买

我检查了苹果开发者论坛和更多的人有同样的问题时,我得到了同样的错误。 https://devforums.apple.com/index.jspa

我希望有朝一日能节省一些时间,因为我花了4个小时左右。