MugunthKumar / MKStoreKit

The "Goto" In App Purchases Framework for iOS 8+
2.09k stars 430 forks source link

expiryDateForProduct triggers an exception when self.purchaseRecord[productId] == null #231

Open jonlidgard opened 9 years ago

jonlidgard commented 9 years ago

-(NSDate*) expiryDateForProduct:(NSString*) productId {

NSNumber *expiresDateMs = self.purchaseRecord[productId]; ---> return [NSDate dateWithTimeIntervalSince1970:[expiresDateMs doubleValue] / 1000.0f]; }

This line causes an exception if expiresDateMs == [NSNull null]; Exception "NSInvalidArgumentException", "-[NSNull doubleValue]: unrecognized selector sent to instance

rcilia commented 9 years ago

I have the same issue. @jonlidgard, did you find a solution to check the expiration?

jonlidgard commented 9 years ago

I just modded the function to return nil if productId == [NSNull null]:

-(NSDate*) expiryDateForProduct:(NSString*) productId {

  NSNumber *expiresDateMs = self.purchaseRecord[productId];
  NSDate *expiryDate;
  if (expiresDateMs && ![expiresDateMs isKindOfClass:[NSNull class]]) {
    expiryDate = [NSDate dateWithTimeIntervalSince1970:[expiresDateMs doubleValue] / 1000.0f];
  }
  return expiryDate;
}