iOS - 恢复自动续订订阅

时间:2012-08-20 09:08:25

标签: iphone ios ios4 in-app-purchase

我正在实施汽车再生订阅。我已经得到了以下问题

用户是否可以在订阅内容过期后恢复订阅内容?

如果是这样,我如何验证它们并让它们下载

2 个答案:

答案 0 :(得分:5)

查看Restoring Auto-Renewable Subscriptions

基本上你需要拨打[[SKPaymentQueue defaultQueue] restoreCompletedTransactions],然后你才能恢复恢复的交易。你应该看看originalTransaction财产。您将知道每笔交易的交易日期(也适用于已过期的交易日期)。然后,您查看产品标识符,您的应用程序应该知道每个产品标识符的订阅长度是多少。由于您知道每笔交易的开始日期和长度,因此您可以计算订阅有效的时间段。 您将它们验证为任何其他事务 - 将它们发送到您的服务器,然后发送到http://buy.itunes.apple.com/verifyReceipt(更改购买到沙箱进行测试)。

答案 1 :(得分:3)

-(void)restoreSubscription:(SKPaymentTransaction *)transaction {
NSUserDefaults *defaultData = [NSUserDefaults standardUserDefaults];
NSArray *productID = [defaultData objectForKey:@"productID"];
NSArray *subMonths = [defaultData objectForKey:@"SubMonth"];

NSLog(@"%@",productID.description);

NSLog(@"Array ==%@",objContantManeger.subscriptionMonth);
NSMutableArray *arrID = [[NSMutableArray alloc] initWithArray:objContantManeger.subscriptionProductID];

NSMutableArray *arrMonth = [[NSMutableArray alloc] initWithArray:subMonths];

NSDate *date;
NSDate *exDate;
for (int i =0;i<arrID.count;i++)
{
    NSString *idStr =[arrID objectAtIndex:i];
    NSString *monthStr = [arrMonth objectAtIndex:i];
    int addsubMonth = [monthStr intValue];

    NSLog(@"%i--%@",i,idStr);
    NSLog(@"%i-->%i",i,addsubMonth);

    NSLog(@"Transaction Date--%@",transaction.originalTransaction.payment.productIdentifier);

    if ([transaction.originalTransaction.payment.productIdentifier isEqualToString:idStr])
    {
        NSLog(@"Date..%@",transaction.originalTransaction.transactionDate);


        date = transaction.originalTransaction.transactionDate;

        NSString *dateStr = [date description];
        NSRange range;

        // year
        range.location = 0;
        range.length = 4;
        NSString *yearStr = [dateStr substringWithRange:range];
        int year = [yearStr intValue];
        NSLog(@"%i",year);

        // month
        range.location = 5;
        range.length = 2;
        NSString *monthStr = [dateStr substringWithRange:range];
        int month = [monthStr intValue];
        NSLog(@"%i",month);
        // day
        range.location = 8;
        range.length = 2;
        NSString *dayStr = [dateStr substringWithRange:range];
        int day = [dayStr intValue];
        NSLog(@"%i",month);

        NSCalendar *calendar = [NSCalendar currentCalendar];

        NSDateComponents *components = [[NSDateComponents alloc] init];
        NSLog(@"addsubMonth---)%i",addsubMonth);
        [components setYear:year];
        [components setMonth:month+addsubMonth];
        [components setDay:day]; 

        NSLog(@"Expire DATE-->%@",[calendar dateFromComponents:components]);

        exDate = [calendar dateFromComponents:components];

        NSUserDefaults *defult = [NSUserDefaults standardUserDefaults];
        [defult setObject:exDate forKey:@"subexpiredate"];
        [defult synchronize];


       // return;

    }
}

您可以使用此方法验证订阅。因为这是提供订阅开始和过期日期。

<强>提示 -

使用应用程序委托方法applicationDidEnterBackground实现检查订阅。