gpt4 book ai didi

objective-c - 如何在ios5中进行应用内购买?

转载 作者:行者123 更新时间:2023-12-04 20:05:45 26 4
gpt4 key购买 nike

我已使用以下代码进行应用内购买。

- (void)viewDidLoad {
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"Can Buy Product");

SKProductsRequest *productRequest=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@"com.mycompany.myproduct.productpack"]];
productRequest.delegate=self;
[productRequest start];
}
else {

NSLog(@"Product Can't be purchased");
}
}

-(IBAction)purchasePack1 {

SKPayment *payment=[SKPayment paymentWithProductIdentifier:@"com.mycompany.myproduct.productpack"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];

}


-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {

validProduct=nil;
int count=[response.products count];
if (count>0) {
NSLog(@"Product Avail");

validProduct=[response.products objectAtIndex:0];
}
else {
NSLog(@"No Product avail");
[purchaseBtn setHidden:TRUE];
}
}


-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {

for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
NSLog(@"Purchasing");
[activityIndicatorObj setHidden:FALSE];
[activityIndicatorObj startAnimating];
break;

case SKPaymentTransactionStatePurchased:

UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"Congrats" message:@"Thanks For Purchasing " delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alt show];
[alt release];
NSLog(@"Purchased");
[activityIndicatorObj stopAnimating];
[activityIndicatorObj setHidden:TRUE];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;

case SKPaymentTransactionStateFailed:

if (transaction.error.code!=SKErrorPaymentCancelled) {

NSLog(@"Cancelled");

}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

UIAlertView *alt1=[[UIAlertView alloc]initWithTitle:@"Sorry" message:@"Some Error Encountered!" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alt1 show];
[alt1 release];
NSLog(@"Failed");
[activityIndicatorObj stopAnimating];
[activityIndicatorObj setHidden:TRUE];
break;

case SKPaymentTransactionStateRestored:
NSLog(@"Restored");
[activityIndicatorObj stopAnimating];
[activityIndicatorObj setHidden:TRUE];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;



default:
break;
}
}
}

当我点击购买按钮时,我收到一条警告消息“您已经购买了该产品但尚未下载,是否要下载?”当我单击"is"时,我没有从 App 收到任何响应,而且我确定该产品尚未下载。谁能告诉我对这个问题的建议。提前致谢。

最佳答案

我没有看到 - (void)provideContent:(NSString *)productId 的任何实现 - 你错过了那部分吗?在任何情况下,当 transactionState 也变为 SKPaymentTransactionStatePurchased 时,您应该会收到通知。

您可能想看看 in-app 上的 Ray Wenderlich tut如果您还没有购买,它将帮助您设置一个应用程序内管理器类。我认为您已将应用程序内逻辑放在 View Controller 中 - 最好将该部分留在单独的类中。所以应用内管理器/助手 :-)

关于objective-c - 如何在ios5中进行应用内购买?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154867/

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