2015-07-03 39 views
0

我试着将应用程序购买添加到我的应用程序,以便用户选择购买没有iAd的应用程序。所以我搜索了一个好的可可豆荚,因为在应用程序购买的实施非常繁重。因为iaphelper似乎是我试图在我的项目中实现它的最好方式,但是正如你所看到的那样,这种方式并不能很好地工作。任何人有一个想法如何使这项工作?如何使用iAPHelper和CocoaPods添加iAP?

// .h 

@interface MenuViewController : UIViewController <ADBannerViewDelegate, SKPaymentTransactionObserver, SKProductsRequestDelegate> 

-(IBAction)removeAds:(UIButton *)sender; 

-(void)AdsRemoved; 

@end 

//.m 

-(IBAction)removeAds:(UIButton *)sender { 
} 

-(void)Purchased { 
    if(![IAPShare sharedHelper].iap) { 
     NSSet* dataSet = [[NSSet alloc] initWithObjects:@"com.comquas.iap.test", nil]; 

     [IAPShare sharedHelper].iap = [[IAPHelper alloc] initWithProductIdentifiers:dataSet]; 
    } 

    [IAPShare sharedHelper].iap.production = NO; 

    [[IAPShare sharedHelper].iap requestProductsWithCompletion:^(SKProductsRequest* request,SKProductsResponse* response) 
    { 
     if(response > 0) { 
      SKProduct* product =[[IAPShare sharedHelper].iap.products objectAtIndex:0]; 

      [[IAPShare sharedHelper].iap buyProduct:product 
             onCompletion:^(SKPaymentTransaction* trans){ 

              if(trans.error) 
              { 
               NSLog(@"Fail %@",[trans.error localizedDescription]); 
              } 
              else if(trans.transactionState == SKPaymentTransactionStatePurchased) { 

               [[IAPShare sharedHelper].iap checkReceipt:trans.transactionReceipt AndSharedSecret:@"your sharesecret" onCompletion:^(NSString *response, NSError *error) { 

                //Convert JSON String to NSDictionary 
                NSDictionary* rec = [IAPShare toJSON:response]; 

                if([rec[@"status"] integerValue]==0) 
                { 
                 NSString *productIdentifier = trans.payment.productIdentifier; 
                 [[IAPShare sharedHelper].iap provideContent:productIdentifier]; 
                 NSLog(@"SUCCESS %@",response); 
                 NSLog(@"Pruchases %@",[IAPShare sharedHelper].iap.purchasedProducts); 
                } 
                else { 
                 NSLog(@"Fail"); 
                } 
               }]; 
              } 
              else if(trans.transactionState == SKPaymentTransactionStateFailed) { 
               NSLog(@"Fail"); 
              } 
             }];//end of buy product 
     } 
    }]; 
} 

回答