hacker
hacker

Reputation: 8947

Autorenewable subscription in-app purchases in iphone?

I have an iPhone application in which I am using Auto renewable subscriptions using MKstorekit4.1.I am successfully implemented it and I'm getting the server responses.Actually I want to use this subscription active for 1 month. I am giving value in the config.plist as 30.But when I'm testing I need to purchase again in the same day? I need that purchase to be active for 30 days. MKstorekit says they have already taken care of it with the following code.Then why I have this scenario.

-(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);        
   }
}

Can anybody help me?

Upvotes: 1

Views: 789

Answers (1)

Nikita Pestrov
Nikita Pestrov

Reputation: 5966

When you are in the sandbox,one month subscription expires every 5 minutes,and after 30 minutes since first purchase it stops auto renewing,so don't get frustrated,when you notice that it doesn't auto renew anymore,or expired before you expected that.

Upvotes: 2

Related Questions