かなり長い質問ですが、理解しやすいので、少しお時間をください :)
数週間前、アプリのショップ ページを作成しました。私はアプリ内購入が初めてで、ネットのコードを入手しました。これは 1 つのオブジェクト用に作成されたので、自分のニーズに合わせてコードを編集することにしました。アプリのプロ版を 1 回購入し、3 種類のコインを 3 回購入します。
コインを購入すると問題なく動作しますが、唯一の問題は、2 回目に購入すると購入したコインの 2 倍の量が追加され、3 回目に購入したコインの量の 3 倍に追加されることです。誰かが見てくれることを願っています。私のコードで、何が悪いのか教えてください。このトピックでは、コードを少し小さくして、すべての購入を表示しません。
//the 100 coins button
-(IBAction)savedata100:(id)sender {
askToPurchase100Munten = [[UIAlertView alloc]
initWithTitle:@"100 Munten"
message:@"Ga verder om 100 Munten te kopen."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Verder", @"Cancel", nil];
askToPurchase100Munten.delegate = self;
[askToPurchase100Munten show];
[askToPurchase100Munten release];
//次のステップ
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
else if (alertView==askToPurchase100Munten) {
if (buttonIndex==0) {
// user tapped YES, but we need to check if IAP is enabled or not.
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"100Munten"]];
Temp = 2;
request.delegate = self;
[request start];
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Prohibited"
message:@"Parental Control is enabled, cannot make a purchase!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
[tmp release];
}
}
}
//次のステップ
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsResponse *)response
{
statusLabel.text = @"";
int count = [response.products count];
}
if (Temp == 2){
if (count>0) {
SKProduct *selectedProduct = [response.products objectAtIndex:0];
SKPayment *payment = [SKPayment paymentWithProduct:selectedProduct];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Not Available"
message:@"No products to purchase"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
[tmp release];
}
}
// 最後のステップ これは、実行するたびに何度も呼び出されているものです (uiView も何度もポップアップします)
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
// show wait view here
statusLabel.text = @"Verwerken...";
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view and unlock feature 2
statusLabel.text = @"Klaar!";
if (Temp == 2){
//ADD COINS WHEN PURCHASES IS COMPLETE
int coinsToAdd = 100;
int currentCoins = [[NSUserDefaults standardUserDefaults] integerForKey:@"savedstring"];
int savestring =
currentCoins + coinsToAdd;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setInteger:savestring forKey:@"savedstring"]; [defaults synchronize];
[label111 setText:[NSString stringWithFormat:@"Munten: %i",[self getCoins]]];
//ALERTVIEW TO SHOW YOU PURCHASED COINS
UIAlertView *tmp2 = [[UIAlertView alloc]
initWithTitle:@"Voltooid"
message:@"Je hebt 100 Munten Gekocht"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp2 show];
[tmp2 release];
誰かが私を助けてくれることを願って読んでくれてありがとう:)