生产时未发送到服务器的应用内购买收据

时间:2014-09-16 16:51:44

标签: ios in-app-purchase appstore-approval

我一直在尝试上传我的应用的新版本,其中包含不续订的应用内购买但没有成功。它被撤销了近两个月,我找不到问题。

当我使用沙箱帐户进行测试时,购买会转到我的服务器,我会对收据进行身份验证,然后更新用户的状态。但是,当我的应用程序进行审核时,审核人员说我的应用程序无法提供用户的付费内容,但我没有在我的服务器上单独尝试。

我对Objective-C代码做了一些更改,希望错误可能是超时,现在我改为 45.0秒。这应该是多长时间?

我还对服务器代码进行了一些更改,以检查是否已通过沙箱或生产帐户进行购买。

所以......这是SKPaymentTransactionStatePurchased之后调用的方法。

#pragma mark pagamento
-(void)completarTransacao:(SKPaymentTransaction *)transacao
{
    [SVProgressHUD dismiss];

    receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle]  appStoreReceiptURL]];

    if (!receipt)
    {
       receipt = transacao.transactionReceipt;
    }

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    [SVProgressHUD showWithStatus:NSLocalizedString(@"Efetuando assinatura...", nil)];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@assinaturaplano/", [[NSDictionary dictionaryWithContentsOfFile:configuracoes_plist] objectForKey:@"Dominio"]]] cachePolicy:nil timeoutInterval:45.0];

    [request setHTTPMethod:@"POST"];

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"];

    [request setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:@"http://temp"]]]];

    NSString *postString = [NSString stringWithFormat:@"receipt=%@&transactionIdentifier=%@&origem=%@", [receipt.base64Encoding urlencode], transacao.transactionIdentifier, [[NSDictionary dictionaryWithContentsOfFile:[home_documents stringByAppendingPathComponent:@"compra"]] objectForKey:@"origem"]];

   [request setHTTPBody:[NSData dataWithBytes:[postString UTF8String] length:postString.length]];

   [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *erro)
   {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

        [SVProgressHUD dismiss];

        if ([(NSHTTPURLResponse*)response statusCode] == 200 || [(NSHTTPURLResponse*)response statusCode] == 201)
        {
            // SUBSCRIPTION CONFIRMED
            [SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"Assinatura efetuada com sucesso!", nil)];

            [[NSNotificationCenter defaultCenter] postNotificationName:@"atualizarGold" object:nil];
        }
        else
        {
            // SUBSCRIPTION NOT CONFIRMED
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"Assinatura não efetuada. Tente novamente.", nil)];
        }

        [[SKPaymentQueue defaultQueue] finishTransaction:transacao];
    }];
}

我的购买方法在审核时总是会转到其他地方。

审核回复

  

原因   2.2:展示错误的应用将被拒绝   ----- 2.2 -----我们发现你的应用程序在运行iOS 8的iPhone和运行iOS 8的iPhone 5s上进行了评论时出现了一个或多个错误   Wi-Fi和蜂窝网络都不符合   App Store评论指南。在App Purchase中没有完成。后   用户点击In App Purchase,输入Apple ID和密码   确认购买,产生错误消息。步骤   重现是:   1.启动应用程序   2.使用提供的凭据登录   3.选择金牌会员资格'   4.点击7天'   5.输入用户的Apple ID和密码   6.确认购买   7.出现错误消息

我做错了什么?为什么它仅适用于沙箱?

1 个答案:

答案 0 :(得分:1)

要查找收据信息,我执行了以下操作:

// Transaction: SKPaymentTransaction
// storeURL: Sandbox - https://sandbox.itunes.apple.com/verifyReceipt | Production - https://buy.itunes.apple.com/verifyReceipt
-(void)validateTransaction:(SKPaymentTransaction *)transaction storeURL:(NSString *)url
{
     receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle]  appStoreReceiptURL]];

     if (!receipt)
     {
         receipt = transacao.transactionReceipt;
     }

     NSError *error;

     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];

     [request setHTTPMethod:@"POST"];

     [request setHTTPBody:[NSJSONSerialization dataWithJSONObject:@{@"receipt-data": [receipt base64EncodedStringWithOptions:0], @"password" : @"yourpassword"} options:0 error:&error]];

     [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {        
         if (!connectionError)
         {
              NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

              if ([[jsonResponse objectForKey:@"status"] intValue] == 0)
              {
                  NSDictionary *purchaseInfo;

                  NSArray *inApp = [[jsonResponse objectForKey:@"receipt"] objectForKey:@"in_app"];

                  if (inApp)
                  {
                      for (NSDictionary *receptDictionary in inApp)
                      {
                          if ([[receptDictionary objectForKey:@"transaction_id"] isEqualToString:transacao.transactionIdentifier])
                          {
                              purchaseInfo = receptDictionary;

                              break;
                          }
                      }
                  }

                  // The recent has been found
                  // Send it to your server
              }
              else
              {
                  switch ([[jsonResponse objectForKey:@"status"] intValue])
                  {
                  case 21003:
                          // Receipt not authenticated

                          [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                          break;
                  case 21005:
                          // Server not available 

                          break;
                 case 21007:
                          // Sandbox receipt send it to sandbox server
                          [self validateTransaction:transaction storeURL:@"https://sandbox.itunes.apple.com/verifyReceipt"];
                          break;
                 case 21008:
                          // Production receipt send it to production
                          [self validateTransaction:transaction storeURL:@"https://buy.itunes.apple.com/verifyReceipt"];
                          break;
                  }
              }
          }
          else
          {
              // It was not possible to connect AppStore
          }
      }];
 }