2012-09-08 147 views
0

我用这个代码来处理我的应用程序内购买:测试应用程序内购买

#pragma mark StoreKit Delegate 

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

      { 

      // show wait view here 
      // statusLabel.text = @"Processing..."; 

       } 
      break; 

     case SKPaymentTransactionStatePurchased: 

       { 

      [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
      // remove wait view and unlock feature 2 
      // statusLabel.text = @"Done!"; 
      UIAlertView *tmp = [[UIAlertView alloc] 
           initWithTitle:@"Complete" 
           message:@"You have unlocked Feature 2!" 
           delegate:self 
           cancelButtonTitle:nil 
           otherButtonTitles:@"Ok", nil]; 
      [tmp show]; 



      NSError *error = nil; 
      [SFHFKeychainUtils storeUsername:@"IAPStoreSave" andPassword:@"whatever" forServiceName:kStoredData updateExisting:YES error:&error]; 

      // apply purchase action - hide lock overlay and 

        [self.lockImage removeFromSuperview]; 

      // do other thing to enable the features 

        } 
      break; 

     case SKPaymentTransactionStateRestored: 
      { 

      [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
      // remove wait view here 
      // statusLabel.text = @""; 

       } 
      break; 

     case SKPaymentTransactionStateFailed: 

      { 

      if (transaction.error.code != SKErrorPaymentCancelled) { 
       NSLog(@"Error payment cancelled"); 
      } 
      [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 
      // remove wait view here 
      // statusLabel.text = @"Purchase Error!"; 

      } 
      break; 

     default: 
      { 

       } 
      break; 
    } 
} 
} 

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response 
{ 

// remove wait view here 
    // statusLabel.text = @""; 

SKProduct *validProduct = nil; 
int count = [response.products count]; 

if (count>0) { 
    validProduct = [response.products objectAtIndex:0]; 

    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.app.ID"]; 
    [[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]; 

} 


} 
-(void)requestDidFinish:(SKRequest *)request 
{ 

} 

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error 
{ 
     NSLog(@"Failed to connect with error: %@", [error localizedDescription]); 
} 

并以这种方式来启动它:

SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.app.ID"]]; 


      request.delegate = self; 

      [request start]; 

在我的iTunes连接我设置在-app输入我已输入的产品ID,状态为“准备提交”,并且还显示:“您的第一次应用程序内购买必须提交一个新的应用程序版本,请从In- “版本详细信息”页面的“应用程序购买”部分,然后点击“准备上传二进制文件”。当我开始请求时,总是显示警报NO PRODUCT AVAILABLE。我究竟做错了什么??

回答

0

您确定套件ID与Itunes Connect上的应用程序相同吗?其次要检查的是应用程序配置文件(如果它处理IAP) - 我认为这可能是原因。让我知道。