gpt4 book ai didi

ios - response.products计数始终返回0 Xcode 4 ios应用程序内购买

转载 作者:行者123 更新时间:2023-12-01 16:47:54 25 4
gpt4 key购买 nike

好吧,当我尝试在模拟器中进行应用内购买时,我的问题很简单,response.products计数始终返回0,因此没有购买...我一直在尝试对其进行调试,但没有成功....这是代码:

- (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;
}
}
}
}

最佳答案

必须确保标识符正确无误。

关于ios - response.products计数始终返回0 Xcode 4 ios应用程序内购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18518785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com