2
那麼我的問題很簡單,當試圖在模擬器中進行應用程序購買時,response.products count總是返回0,因此不購買...我一直試圖調試但沒有成功....這裏是代碼:response.products count始終返回0 Xcode 4 ios應用程序內購買
- (IBAction)buy500Coins:(id)sender {
[buyingAI startAnimating];
if (internetActive == NO) {
[buyingAI stopAnimating];
askToPurchase = [[UIAlertView alloc]
initWithTitle:@"No internet connection"
message:@"It seems you are not connected to the internet. in-app purchases require a internet connection. Please connect to the internet and try again."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[askToPurchase show];
} else {
askToPurchase = [[UIAlertView alloc]
initWithTitle:@"Are you Sure?"
message:@"Are you sure you want to buy 4000 coins for 0.99$?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
askToPurchase.delegate = self;
[askToPurchase show];
[buyingAI stopAnimating];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView == askToPurchase) {
if (buttonIndex == 1) {
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.ge0rges.Meme_jump.500C"]];
request.delegate = self;
[request start];
[buyingAI startAnimating];
buyingAI.hidden = NO;
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Prohibited"
message:@"Sorry , Parental Control is enabled, you cannot make a purchase."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[tmp show];
}
}
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
[buyingAI stopAnimating];
SKProduct *validProduct = nil;
int count = [response.products count];
NSLog(@"%i", count);
if (count>0) {
validProduct = [response.products objectAtIndex:0];
SKPayment *payment = [SKPayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment]; // <-- KA CHING!
} else {
UIAlertView *notAvail = [[UIAlertView alloc]
initWithTitle:@"Not Available"
message:@"Sorry there seems to be a problem. Please try again later."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[notAvail show];
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
{
[buyingAI startAnimating];
buyingAI.hidden = NO;
break;
}
case SKPaymentTransactionStatePurchased:
{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[buyingAI stopAnimating];
UIAlertView *complete = [[UIAlertView alloc]
initWithTitle:@"Complete"
message:@"You have received 4000 Coins."
delegate:nil
cancelButtonTitle:@"Awesome!"
otherButtonTitles:nil, nil];
[complete show];
allCoins += 4000;
break;
}
case SKPaymentTransactionStateRestored:
{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[buyingAI stopAnimating];
break;
}
case SKPaymentTransactionStateFailed:
{
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *failed = [[UIAlertView alloc]
initWithTitle:@"Failed"
message:@"Oops there seems to be a problem. Please try again later and make sure your internet connection is active."
delegate:nil
cancelButtonTitle:@"Ok :("
otherButtonTitles:nil, nil];
[failed show];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[buyingAI stopAnimating];
break;
}
}
}
}
'invalidProductIdentifiers'的內容是什麼? iTunesConnect中產品的狀態如何? – Wain
iTunes連接表示它已準備好提交應用內購買。我如何獲取invalidProductIdentifiers的內容? – ge0rges
從'SKProductsResponse' – Wain