2012-08-30 211 views
2

在我的應用程序,我必須在應用程序purchse實施下面的scenerio: - 應用程序是免費的所有用戶,即每個人都可以免費下載。 我已經爲此實現了易耗品類型。 在應用程序中有一個選項購買$ 1.99.once 10個硬幣用戶購買它完成交易成功 但是當再次用戶點擊購買到10個硬幣時,它提示「您已經下載了這個應用程序」。 我想在該應用程序購買實施該笏,以便用戶可以購買10個硬幣的多種類型? 這將是什麼類型和場景。在應用購買實施

請建議?

+0

即用戶可以多次購買10個硬幣? – yadav

+0

你確定這個類型是_consumable_? – holex

+0

是類型是消耗品。 – yadav

回答

0
- (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"]){ 
    [email protected]"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]; 
    } 
+3

在沒有任何形式的評論的情況下發布這麼多的代碼並不是真的有用,它也沒有正確縮進。 – doge