MKStoreKit icon indicating copy to clipboard operation
MKStoreKit copied to clipboard

Where i have to call refreshAppStoreReceipt

Open Sajanrav01 opened this issue 9 years ago • 6 comments

I am currently working with Auto-renewbalae subscription.My problem is that after completing successful purchasing i print the purchase details.but it return null.

The Purchase details is like that

Purchased/Subscribed to product with id: com.cName.aName.Auto purchaseRecord { " com.cName.aName.Auto" = "null"; }

When am trying to call expiryDateForProduct ,This will crash due to Null value

I am not calling any refreshAppStoreReceipt method from any where

Let me know why this is happening,Please help me

Thanks

Sajanrav01 avatar Mar 25 '15 07:03 Sajanrav01

the same here, it always set the value to null

@salibabu, did you find the solution for this

ivanstojkovicapps avatar Apr 05 '15 10:04 ivanstojkovicapps

it seams to work, the first time the value is NSNull, so @MugunthKumar you change following method, otherwise it crashes:

-(NSDate_) expiryDateForProduct:(NSString_) productId {

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

ivanstojkovicapps avatar Apr 05 '15 12:04 ivanstojkovicapps

@ivanstojkovicapps, I had the same issue and your change fixed the crash, but for me, the value is always NSNull, even after the receipt validation. Actually, if you look at the "startValidatingReceiptsAndUpdateLocalStoreWithCompletionBlock" method (around line 380 in MKStoreKit.m), it seems that the expires date is set only if a "previouslyStoredExpiresDateMs" is not NSNull, which is never the case since we never set a date before.

Do you have any idea of what could be wrong?

rcilia avatar May 28 '15 15:05 rcilia

Any updates? Still doesn't work

denis-minnetdinov avatar Mar 15 '16 13:03 denis-minnetdinov

I have added the following to the object enumerator which seems to have fixed the problem. I've only tested this once or twice so I'm not sure if it's broken anything else. However the code I've added just checks to see if the previously set date is null. If it is it will check to see if the expiry date is in the future and if so it will save to the purchase record.

              [receipts enumerateObjectsUsingBlock:^(NSDictionary *receiptDictionary, NSUInteger idx, BOOL *stop)
              {
                  NSString *productIdentifier = receiptDictionary[@"product_id"];
                  NSNumber *expiresDateMs = receiptDictionary[@"expires_date_ms"];
                  NSNumber *previouslyStoredExpiresDateMs = self.purchaseRecord[productIdentifier];
                  if (expiresDateMs && ![expiresDateMs isKindOfClass:[NSNull class]] && ![previouslyStoredExpiresDateMs isKindOfClass:[NSNull class]]) {
                      if ([expiresDateMs doubleValue] > [previouslyStoredExpiresDateMs doubleValue]) {
                          self.purchaseRecord[productIdentifier] = expiresDateMs;
                          purchaseRecordDirty = YES;
                      }
                  }
                  if (expiresDateMs && ![expiresDateMs isKindOfClass:[NSNull class]] && [previouslyStoredExpiresDateMs isKindOfClass:[NSNull class]]) {
                      double currentTimeInMs = (double)[[NSDate date] timeIntervalSince1970] * 1000;
                      if ([expiresDateMs doubleValue] > currentTimeInMs) {
                          self.purchaseRecord[productIdentifier] = expiresDateMs;
                          purchaseRecordDirty = YES;
                      }
                  }
              }];

joshgare avatar Jun 26 '17 13:06 joshgare

@joshgare Thank you very much, this fix seems to ensure expiry dates are kept upto date for me(I also changed the MKStoreKit singleton accessor +(MKStoreKit *)sharedKit to always call:

[_sharedKit startValidatingReceiptsAndUpdateLocalStore];

So far this seems to work for me :) However, I'm not keen on changing library code, but it seems this repo is no longer maintained?

AliMunchkin avatar Mar 12 '19 15:03 AliMunchkin