2011-05-03 156 views
7

雖然測試應用內購買在設備上的沙箱環境,我記錄了以下錯誤:蘋果在應用程序內購買

錯誤域= 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

回答

3

這可能是可笑的,但是 - 如果你肯定你的代碼是正確的 - 做硬重置您的iPod(設置(全抹)=>常規=>重置=>抹掉所有內容和「設置」)。

+0

有沒有可能沙箱服務器停機?你不認爲我在這裏附上的代碼是正確的嗎? – 2011-05-04 10:14:51

+0

你在這裏給出的答案是部分正確的。 – 2011-05-05 16:42:02

1

如果您使用其他iTunes帳戶登錄,也會發生這種情況。要測試在沙箱中的應用程序內購買,您需要從設置中的任何其他帳戶註銷。然後啓動你的應用程序和做應用程序購買。當您的帳戶被要求輸入您創建的iTunes測試帳戶。這樣你的沙盒環境就可以完美工作。希望這會有所幫助。

0

也許沙盒服務器已關閉。

我能夠獲得的產品信息,但要求購買

我檢查了蘋果開發者論壇和更多的人有同樣的問題時,我得到了同樣的錯誤。 https://devforums.apple.com/index.jspa

我希望有朝一日能節省一些時間,因爲我花了4個小時左右。