2012-08-03 61 views
0

設置我的應用程序內購買創建兩個包的ID。我創建了一個測試帳戶,並檢查了我的應用程序purchase..it是工作完全正常......一個星期後,後來當我測試即時得到這個錯誤*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array' *** First throw call stack:其未歸還的產品...可以ü人幫助我out.what可能可能是不對的在應用程序內購買不工作

-(void)Declarations 
{ 
if ([SKPaymentQueue canMakePayments]) { 

    NSLog(@"parental functions are disabled"); 
    SKProductsRequest *productRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObjects:@"com.techzone.9xo.onedollar",@"com.techzone.9xo.twodollar",nil]]; 
    productRequest.delegate=self; 
    [productRequest start]; 
}else { 
    NSLog(@"parental functions are enabled"); 
} 

} 
    -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsResponse *)response 
{ 
SKProduct *validProduct=nil; 
int count = [response.products count]; 
NSLog(@"number of prouducts present:%d",count); 

if(_HintValue) 
{ 
    validProduct = [response.products objectAtIndex:0]; 

} 
if (!_HintValue) { 
    validProduct = [response.products objectAtIndex:1]; 
} 
NSLog(@"the product is :%@",validProduct.localizedTitle); 
SKPayment *skpayment = [SKPayment paymentWithProduct:validProduct]; 
[[SKPaymentQueue defaultQueue] addPayment:skpayment]; 
[[SKPaymentQueue defaultQueue]addTransactionObserver:self]; 

} 
    - (void)request:(SKRequest *)request didFailWithError:(NSError *)error 
    { 
    NSLog(@"Failed to connect with error: %@", [error localizedDescription]); 

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

    switch (transaction.transactionState) { 
     case SKPaymentTransactionStatePurchasing: 
      NSLog(@"stuff is getting purchased"); 
      break; 
     case SKPaymentTransactionStatePurchased: 
      NSLog(@"purchased properly"); 
      NSInteger currentValue=[Util getIntegerValueForKey:@"hintValue"]; 
      if(_HintValue) 
      [Util setIntegerValue:10+currentValue forKey:@"hintValue"]; 
      if (!_HintValue) 
      [Util setIntegerValue:25+currentValue forKey:@"hintValue"]; 
      [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 
      break; 
     case SKPaymentTransactionStateRestored: 
      [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 
      break; 
     case SKPaymentTransactionStateFailed: 
      if (transaction.error.code != SKErrorPaymentCancelled) { 
       NSLog(@"error happened"); 
      } 
      [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 
      break; 
     default: 
      break; 
    } 
    } 
    } 

回答

2

的問題是,你得到有效的產品ID的空列表。您正在訪問創建該錯誤的空數組的objectAtIndex:0

,如果您檢查response.invalidProductIdentifiers,你會發現你的產品ID那裏。

不幸的是,可以有許多原因。看看這個checklist of reasons可能導致無效的產品ID。

+0

的東西是它的前一週做工精細,但今天它不是...任何想法...我還沒有發佈的應用程序yet..and I M使用測試帳戶 – user578386 2012-08-03 06:28:32

+0

測試它,我有同樣的問題。看起來有時沙箱AppStore(用於測試)已關閉。但通常不會超過幾個小時。如果你的問題仍然存在,你應該看一下清單,但如果它是以前的工作,而且你還沒有改變任何東西,我的猜測就是沙箱已經關閉。 – joern 2012-08-03 06:34:17

+0

如果您從設備中刪除應用程序並清理項目,它仍然不會受到傷害。如果你還沒有這樣做。 – joern 2012-08-03 06:35:02