恢复应用内购买是不是适用于 iTunes Connect 上的测试帐户?

Posted

技术标签:

【中文标题】恢复应用内购买是不是适用于 iTunes Connect 上的测试帐户?【英文标题】:Does restoring in-app purchases work with test accounts on iTunes Connect?恢复应用内购买是否适用于 iTunes Connect 上的测试帐户? 【发布时间】:2014-06-07 23:07:55 【问题描述】:

采购工作完美。但无法从 iTunes Connect 上的测试帐户恢复应用内购买。这是正确的吗?我使用以下代码恢复购买:

... 
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];


// called when a transaction has been restored and and successfully completed
- (void)restoreTransaction:(SKPaymentTransaction *)transaction 
    [self recordTransaction:transaction.originalTransaction];
    [self provideContent:transaction.originalTransaction.payment.productIdentifier];
    [self finishTransaction:transaction wasSuccessful:YES];


// saves a record of the transaction by storing the receipt to disk
- (void)recordTransaction:(SKPaymentTransaction *)transaction 
    if ([transaction.payment.productIdentifier isEqualToString:[self getProductId:gFullVersion]]) 
        // save the transaction receipt to disk
        [[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:[self getProductId:gFullVersion]];
        [[NSUserDefaults standardUserDefaults] synchronize];
    


// removes the transaction from the queue and posts a notification with the transaction result
- (void)finishTransaction:(SKPaymentTransaction *)transaction wasSuccessful:(BOOL)wasSuccessful 
    // remove the transaction from the payment queue.
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

    NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:transaction, @"transaction" , nil];
    if (wasSuccessful) 
        // send out a notification that we’ve finished the transaction
        [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:userInfo];
     else 
        // send out a notification for the failed transaction
        [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionFailedNotification object:self userInfo:userInfo];
    

应用程序显示输入 AppleID 密码的对话框。

【问题讨论】:

当你输入你的 Apple ID 密码时会发生什么? 在使用测试帐户的开发中恢复应该可以正常工作。 什么也没发生。现在恢复不起作用。但它以前使用相同的代码工作。 App Store 的测试账户似乎有问题。恢复停止在所有具有测试帐户的设备上工作。有人可以查吗? 也许您不小心尝试在沙箱之外使用您的测试帐户,这会使测试用户无效并且它不再正常工作。 test user 【参考方案1】:

我发现了问题。我有两个非消耗性应用程序内。一个被删除。一个是活跃的。以下代码仅返回应用内删除:

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

所以,问题出在 App Store...

附:当我再次购买它时,它是免费的,所以真的制作了两个应用内。

【讨论】:

你能在这里详细说明一下吗。您是说您无法使用沙盒帐户测试恢复应用内购买吗?谢谢!【参考方案2】:

我按照这个恢复按钮的代码。

  -(void)restoreButtonTapped

  [[RMStore defaultStore] restoreTransactionsOnSuccess:^
                NSLog(@"Restored Successfully");
                [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                [apDelegate hideLoading];
                BOOL isExpired = [self isPurchaseExpired:[NSDate date]]; // DEV-TODO: again fetching the expireDate from user Defaults in the method, so just sending the current Date.
                if (!isExpired)
                
                    [self moveToLoginScreen];
                
                else
                
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title" message:@"Product expired, Please buy the product for uninterrupted services." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                    [alert show];
                
             failure:^(NSError *error) 
                [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                NSLog(@"Failed to restore Completed Transactions");
                [apDelegate hideLoading];
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"MDPulse" message:@"Failed to restore Transactions. Please try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show];
            ];
        


  




   - (void)restoreCompletedTransactions
  
    NSLog(@"Restore Tapped in transaction process");
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
  

  - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
  
NSLog(@"Restore completed transactions finished.");
NSLog(@" Number of transactions in queue: %d", [[queue transactions] count]);
for (SKPaymentTransaction *trans in [queue transactions])
  
    NSLog(@" transaction id %@ for product %@.", [trans transactionIdentifier], [[trans payment] productIdentifier]);
    NSLog(@" original transaction id: %@ for product %@.", [[trans originalTransaction] transactionIdentifier],
          [[[trans originalTransaction] payment]productIdentifier]);


    if ([[[trans payment] productIdentifier] isEqual: kMDPulseSubscriptionProductIdentifier]) 

        NSLog(@"Purchase Restored");

        // Do your stuff to unlock
    
  
  

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error 
NSLog(@"%s","User Cancel.");

MedPulseAppDelegate *appdelegate =( MedPulseAppDelegate *)[[UIApplication sharedApplication]delegate];
[appdelegate hideLoading];



- (void)restoreTransaction:(SKPaymentTransaction *)transaction 
NSLog(@"restoreTransaction...");

[self validateReceiptForTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
 

欢迎!

我想这会对你有所帮助。

【讨论】:

以上是关于恢复应用内购买是不是适用于 iTunes Connect 上的测试帐户?的主要内容,如果未能解决你的问题,请参考以下文章

尽管没有iTunes帐户登录,iOS仍会恢复应用内购买

iTunes中的报亭启用问题[关闭]

消耗品应用内购买是不是适用于不同的轮胎?

您是不是需要在生产中使用应用内购买功能/授权才能让用户使用 SKStoreProductViewController 在 iTunes 上购买歌曲?

如何确认应用内购买是不是真的对测试 iTunes Connect 用户有效?

区分应用内 iTunes 的产品