9

我正在实施自动更新订阅。我有以下问题

订阅内容过期后用户能否恢复?

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

4

2 回答 2

5

查看恢复自动更新订阅

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

于 2012-08-20T09:21:52.573 回答
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 实现检查订阅。

于 2012-08-20T10:37:17.183 回答