我有一个 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);
}
}
有谁能够帮助我?