Iphone 应用内购买实施

Iphone 应用内购买实施,iphone,objective-c,ipad,in-app-purchase,Iphone,Objective C,Ipad,In App Purchase,在我的应用程序中,我必须在以下场景中实现应用程序内购买:- 应用程序对所有用户都是免费的,即每个人都可以免费下载。 我已经为此实现了消耗品类型。 在应用程序中,用户可以选择以1.99美元购买10枚硬币。一旦用户购买,即可成功完成交易 但当用户再次点击购买的10枚硬币时,它会提示“您已经下载了这个应用程序”。 我想在该wat中实现应用内购买,以便用户可以购买10枚硬币的多种类型? 这将是什么类型和场景 请建议?即用户可以多次购买10枚硬币?您确定该类型是可消费的吗?我正在测试我的应用程序内购买应用

在我的应用程序中,我必须在以下场景中实现应用程序内购买:- 应用程序对所有用户都是免费的,即每个人都可以免费下载。 我已经为此实现了消耗品类型。 在应用程序中,用户可以选择以1.99美元购买10枚硬币。一旦用户购买,即可成功完成交易 但当用户再次点击购买的10枚硬币时,它会提示“您已经下载了这个应用程序”。 我想在该wat中实现应用内购买,以便用户可以购买10枚硬币的多种类型? 这将是什么类型和场景


请建议?

即用户可以多次购买10枚硬币?您确定该类型是可消费的吗?我正在测试我的应用程序内购买应用程序。当我在沙盒环境中使用我的用户帐户第二次购买消耗品时,它总是向我显示一个警报“你已经购买了这个,但它还没有下载。点击“确定”立即下载它。”发布这么多代码而没有任何形式的注释并没有真正的帮助,它也没有正确缩进。
  - (void)requestProductData {
  //  NSLog(@"%@",strCheck);
if ([strCheck isEqualToString:@"inApp"]) {
    myString = strCheck;
    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:            [NSSet setWithObject:@"All_labelling"]];
    request.delegate = self;

    [request start];
}

    }
    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
      NSArray *myProduct = response.products;

  SKPayment *payment = [SKPayment paymentWithProduct:[myProduct objectAtIndex:0]];
  [[SKPaymentQueue defaultQueue] addPayment:payment];

      [request autorelease];
   }


    - (void)inAppPurchase {

      reachability = [Reachability reachabilityForInternetConnection];

      NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];



       if(remoteHostStatus == NotReachable) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"LeaderFollow!" message:@"Network is not found" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
         [alert show];
         [progInd stopAnimating];
          [progInd setHidden:YES];
       }

else if ([SKPaymentQueue canMakePayments]) {
    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [self requestProductData];


}
else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please enable the ability to make purchases." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
  }
    }


   - (void)finishMyTransaction:(SKPaymentTransaction *)transaction {
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
self.view.userInteractionEnabled=YES;
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
    [progInd stopAnimating];
    [progInd setHidden:YES];

   }

   #pragma mark Payment Delegate
   #pragma mark -

   - (void)recordTransaction:(SKPaymentTransaction *)transaction {
   }


    - (void)provideContent:(NSString *)productIdentifier {


   if([productIdentifier isEqualToString:@"All_labelling"]){
    strCheck=@"inApp";
    myString=strCheck;

   }
   if ([strCheck isEqualToString:@"inApp"]){
    [prefs setBool:YES forKey:@"inApp"];
    if(!isTapped){

        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Congratulations!" message:@"You Have Successfully Purchased All Objects Pack" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
    [self viewWillAppear:YES];
   }



//}


  [progInd stopAnimating];
  [progInd setHidden:YES];


  }

  - (void)completeTransaction:(SKPaymentTransaction *)transaction {

[self recordTransaction:transaction];
     [self provideContent:transaction.payment.productIdentifier];

    [self finishMyTransaction:transaction];
  }

  -(IBAction)btnRestoreTapped{
    [progInd setHidden:NO];
    [progInd startAnimating];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
    [[UIApplication sharedApplication]beginIgnoringInteractionEvents];



   }



    - (void)restoreTransaction: (SKPaymentTransaction *)transaction {

[self recordTransaction:transaction];
     [self provideContent:transaction.originalTransaction.payment.productIdentifier];

     [self finishMyTransaction:transaction];

    }


     - (void)failedTransaction: (SKPaymentTransaction *)transaction {

 if (transaction.error.code != SKErrorPaymentCancelled) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:[transaction.error localizedDescription]
                                                    delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
         }

    [self finishMyTransaction:transaction];
      }


       - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
    switch (transaction.transactionState) {

        case SKPaymentTransactionStatePurchased:
            [self completeTransaction:transaction];

            break;

        case SKPaymentTransactionStateFailed:
            [self failedTransaction:transaction];

            break;

        case SKPaymentTransactionStateRestored:

            [self restoreTransaction:transaction];

            break;

        default:
            break;
       }

     }

     }
      - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue{
       [progInd stopAnimating];
        [progInd setHidden:YES];
         [[UIApplication sharedApplication]endIgnoringInteractionEvents];
         if([prefs boolForKey:@"inApp"]){
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"LeaderFollow!" message:@"You Have Successfully Restored   Pack(s)" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        [prefs setObject:@"YES" forKey:@"Restore"];
        }
        else{
           UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"LeaderFollow!" message:@"No purchases to restore" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
           [alert show];
          [alert release];
     }
       isTapped=NO;
      }

     - (void)paymentQueue:(SKPaymentQueue*)queue restoreCompletedTransactionsFailedWithError:(NSError*)error
     {
      [[UIApplication sharedApplication]endIgnoringInteractionEvents];
      [progInd stopAnimating];
      isTapped=NO;
      self.view.userInteractionEnabled=YES;
       [progInd setHidden:YES];
   }