2012-08-30 3 views
2

내 앱에서 아래의 scenerio에서 앱 구입을 구현해야합니다. - 앱은 모든 사용자가 무료로 사용할 수 있습니다. 즉 모든 사용자가 무료로 사용할 수 있습니다. 저는 이것을 위해 Consumable 타입을 구현했습니다. 응용 프로그램에 $ 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