2013-10-07 48 views
1

我剛剛在我的應用程序中添加了iAP,並且出現錯誤。無法獲得SKProductsResponse產品:response.count = 0

- (void)getProductID { //runs on viewdidload 
    if ([SKPaymentQueue canMakePayments]) { 
     SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects:_productID, nil]]; 
     request.delegate = self; 

     [request start]; 
    } else { 
     [[[UIAlertView alloc] initWithTitle:@"Serpentine" message:@"Error: Could not connect to store. Try enabling in-app-purchases in settings." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 

     [self couldNotConnectToStore]; 
    } 

} 

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { 
    for (SKPaymentTransaction *transaction in transactions) { 
     switch (transaction.transactionState) { 
      case SKPaymentTransactionStatePurchased:[self unlockPurchase]; 
       [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 

      case SKPaymentTransactionStateFailed:NSLog(@"Transation Failed"); 
       [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 

      default:break; 
     } 
    } 
} 

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { 
    NSArray *products = response.products; 

    if (products.count != 0) { 
     _product = products[0]; 
     _allowPurchase = YES; 
    } else { 
     [[[UIAlertView alloc] initWithTitle:@"Serpentine" message:@"Error: Could not connect to store" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];//this line of code runs a second after the controller opens 

//****************** error on line above ********************************* 

     [self couldNotConnectToStore]; 
    } 

    products = response.invalidProductIdentifiers; 

    for (SKProduct *product in products) { 
     NSLog(@"Product not found: %@", product); 
    } 
} 


- (IBAction)purchaseButtonPressed:(UIButton *)sender { 
    if (sender.tag == 1) { 
     //buy 20 
     _productID = @"com.piguygames.serpentine.buy20"; 

     SKPayment *payment = [SKPayment paymentWithProduct:_product]; 
     [[SKPaymentQueue defaultQueue] addPayment:payment]; 

    } else if (sender.tag == 2) { 
     //buy 45 
    } else if (sender.tag == 3) { 
     //buy 100 
    } else if (sender.tag == 4) { 
     //double 
    } else if (sender.tag == 5) { 
     //remove ads 
    } 
} 

注意:控制器中還有一些其他代碼,但我認爲它不相關。

我已將應用內購買添加到iTunes連接,並顯示「準備提交」。那麼這裏應該沒問題嗎?此外,我在同一網站上發出警告,說我必須提交我的應用程序的新版本才能進行應用程序購買。我決定先提交我的應用程序並先在應用程序中禁用iAP,然後在稍後的更新中發佈iAP。你需要提交一個新版本來測試iAP嗎?

無論如何,你有什麼問題可以看到到目前爲止?

如果需要更多信息,請確認索取更多信息,我是這個主題的初學者。 謝謝

+0

如果在10個小時內有任何問題不能回答,我必須現在上牀睡覺。謝謝 – Dylanthepiguy

+0

您確定您傳遞給initWithProductIdentifiers的_productID:是不是零? –

+0

您是否在您的流程中使用您的測試帳戶?您應該 - 如果不在iTunes連接中創建一個。在你的正常賬戶上它不會工作。 –

回答

0

請確保您已在「設置」應用中退出任何iTunes帳戶,除非它是您在iTunes Connect中創建的測試帳戶。我最近有這個完全相同的問題,這就是我解決它的方法。

+0

我已經退出了,我已經做了一個測試帳戶,但測試帳戶是要求我做正常註冊的東西在應用商店 – Dylanthepiguy

+0

我一直聽到的這個沙箱模式是什麼?我如何啓用它? – Dylanthepiguy

+0

您不必啓用沙盒環境。只需從應用程序商店註銷,然後在運行應用程序之後,在請求憑證時使用測試帳戶憑證。 對於註冊的東西,請嘗試創建美國國家的測試用戶,然後嘗試。希望它可以幫助你! –