在iphone中自动续订订阅应用内购买?

时间:2012-04-05 15:24:41

标签: iphone in-app-purchase

我有一个iPhone应用程序,其中我正在使用MKstorekit4.1使用自动可再生订阅。我成功实现了它并且我得到服务器响应。实际上我想使用此订阅活动1个月。我在config.plist中给出的值为30.但是当我测试时我需要在同一天再次购买?我需要购买该活动30天。 MKstorekit说他们已经用以下代码处理了它。然后我就有了这个场景。

-(BOOL) isSubscriptionActive
{    
if([[self.verifiedReceiptDictionary objectForKey:@"receipt"] objectForKey:@"expires_date"]){

    NSLog(@"%@",self.verifiedReceiptDictionary);
    NSTimeInterval expiresDate = [[[self.verifiedReceiptDictionary objectForKey:@"receipt"] objectForKey:@"expires_date"] doubleValue]/1000.0;
    NSLog(@"%f",expiresDate);
     NSLog(@"%f",[[NSDate date] timeIntervalSince1970]);
    return expiresDate > [[NSDate date] timeIntervalSince1970];

}else{

    NSString *purchasedDateString = [[self.verifiedReceiptDictionary objectForKey:@"receipt"] objectForKey:@"purchase_date"];        
    if(!purchasedDateString) {
        NSLog(@"Receipt Dictionary from Apple Server is invalid: %@", verifiedReceiptDictionary);
        return NO;
    }
      NSLog(@"%@",purchasedDateString);
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    //2011-07-03 05:31:55 Etc/GMT
    purchasedDateString = [purchasedDateString stringByReplacingOccurrencesOfString:@" Etc/GMT" withString:@""];    
    NSLocale *POSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    [df setLocale:POSIXLocale];        
    [df setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];            
    [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *purchasedDate = [df dateFromString: purchasedDateString];        
    int numberOfDays = [purchasedDate timeIntervalSinceNow] / (-86400.0);
        NSLog(@"%@",purchasedDate);
         NSLog(@"%@",numberOfDays);
    return (self.subscriptionDays > numberOfDays);        
   }
}

有人能帮助我吗?

1 个答案:

答案 0 :(得分:2)

当您在沙箱中时,一个月订阅每5分钟到期,自首次购买后30分钟后停止自动续订,所以当您发现它不再自动续订时,请不要感到沮丧,或者在您预期之前过期。