【问题标题】:How to handle failure while delivering content after In App Purchase?应用内购买后交付内容失败如何处理?
【发布时间】:2013-06-17 10:54:38
【问题描述】:

我有一个使用应用内购买的 iOS 应用。

它使用消耗型产品,当用户购买该产品时,他/她可以将音频上传到服务器。

一旦InAppPurchase成功,数据就会上传到服务器。

InAppPurchase成功但上传失败的情况如何处理? 我们不应该让用户再次购买产品,所以我将上传是否成功存储在用户默认值中。

这里是代码

SKProduct *productToBuy = //product to buy.
if ([[[NSUserDefaults standardUserDefaults] objectForKey:productToBuy.productIdentifier] boolValue]) //if the user has already bought the product and it failed to upload, then just try to upload without buying..
{
    NSLog(@"already purchased, uploading");
    [self uploadRecording];
}
else //if not, then make the user purchase and then upload
{
    [[CGInAppPurchaseManager sharedManager] buyProduct:productToBuy withCompletionBlock:^(SKPaymentTransaction *paymentTransaction, BOOL success) {
        if (success)
        {
            [self uploadRecording];
        }
        else
        {
            if (paymentTransaction.error.code != SKErrorPaymentCancelled)
            {
                NSLog(@"Cancelled transaction");
            }
        }
    }];
}

uploadRecording 代码如下所示

- (void)uploadRecording
{
    NSURL *urlOfAudio = //url of audio file

    [self.model uploadAdOrDedicationWithTitle:title audioData:[NSData dataWithContentsOfURL:urlOfAudio] withCompletionBlock:^(id obj, NSInteger errCode, NSString *errorDescription) {
    SKProduct *productToBuy = self.adParams[@"product"];
    if (obj)
    {
        //if its successfully uploaded set false that the user has already bought a product with this identifier
        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:productToBuy.productIdentifier];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    else
    {
        //when there is an error set true that the user has already bought a product with this identifier
        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:productToBuy.productIdentifier];
        [[NSUserDefaults standardUserDefaults] synchronize];                                                

        //show appropriate error message
        //"An error occured while uploading your broadcast. You will not be made to purchase the product again the next time you try to upload a recording for the same product."
    }
  }];
}

这样好吗?或者有没有更好的方法来处理这个问题?

【问题讨论】:

    标签: ios in-app-purchase


    【解决方案1】:

    理想情况下,您应该退款,但这是不可能的,因此您只能尝试最小化并尽可能以最佳方式解决问题。您的解决方案似乎是您至少可以做的补救措施。此外,如果有办法进行一些验证以检查上传是否可能在实际上传之前运行(使用the Reachability API 或更好地连接到您的服务器以进行快速可用性检查),那么这将最大限度地降低风险发生这种情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-03
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多