我剛剛在我的應用程序中添加了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嗎?
無論如何,你有什麼問題可以看到到目前爲止?
如果需要更多信息,請確認索取更多信息,我是這個主題的初學者。 謝謝
如果在10個小時內有任何問題不能回答,我必須現在上牀睡覺。謝謝 – Dylanthepiguy
您確定您傳遞給initWithProductIdentifiers的_productID:是不是零? –
您是否在您的流程中使用您的測試帳戶?您應該 - 如果不在iTunes連接中創建一個。在你的正常賬戶上它不會工作。 –