我是 iOS 新手,我正在尝试从我的服务中下载 3 个产品,但用户需要购买这些产品,我有 3 个按钮,我点击第一个按钮,输入用户名和密码后,正在下载,然后我点击第二个产品,首先是下载第一个产品然后是第二个产品,然后我点击第三个产品,它正在下载第一个->第二个->第三个产品。下载第一个产品后如何从队列中删除第一个产品?对不起,我的英语不好。
谢谢。
此致。
- (IBAction)downloadButtonPressed:(id)sender {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.company.testtest123"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]addPayment:payment];
}
- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
// Count down
@synchronized(self) {
NSInteger numOfTransaction = [[NSUserDefaults standardUserDefaults] integerForKey:@"NumberOfTransactions"];
[[NSUserDefaults standardUserDefaults] setInteger:numOfTransaction-1 forKey:@"NumberOfTransactions"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
SKProduct *validProduct =nil;
int count = [response.products count];
if (count>0) {
validProduct =[response.products objectAtIndex:0];
}else if(!validProduct){
NSLog(@"No products avaible");
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:{
//download kismi buraya
NSLog(@"_mainDict = %@",_mainDict);
float _csize = (float) 0 / 1024;
float _tsize = (float) [[_mainDict valueForKey:@"Size"] integerValue] / 1024;
NSString *strDownload = [NSString stringWithFormat:@"downloading \n (%0.2f MB/%.2f MB)",_csize,_tsize];
[SVProgressHUD showProgress:0 status:strDownload maskType:SVProgressHUDMaskTypeBlack];
[service servicePicList];
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
}
case SKPaymentTransactionStateRestored:{
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
}
case SKPaymentTransactionStateFailed:
{
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"An error encountered");
}
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
}
}
}
}
- (void)failedTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"failedTransaction...");
if (transaction.error.code != SKErrorPaymentCancelled)
{
NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}