Ravindhiran
Ravindhiran

Reputation: 5384

check In App Purchase Auto Renewable Subscription is valid

I am new to IOS. currently working on in app purchase implementation in my newsstand app.i have implemented auto renewable subscription in my newsstand app.how can i check in app purchase auto renewable subscription is valid or not?

Upvotes: 1

Views: 1763

Answers (2)

Clover03ti05
Clover03ti05

Reputation: 401

Today, I have trouble with this problem. Follow Apple doc here, I used this way to check subscription is expired or not.

This is my code in Objective-C.

NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:resData options:0 error:&error]; 
// this is response from AppStore
NSDictionary *dictLatestReceiptsInfo = jsonResponse[@"latest_receipt_info"];
long long int expirationDateMs = [[dictLatestReceiptsInfo valueForKeyPath:@"@max.expires_date_ms"] longLongValue];
long long requestDateMs = [jsonResponse[@"receipt"][@"request_date_ms"] longLongValue];
isValidReceipt = [[jsonResponse objectForKey:@"status"] integerValue] == 0 && (expirationDateMs > requestDateMs);

Hope this help.

Upvotes: 0

Richard Brown
Richard Brown

Reputation: 11444

When you create the subscription you need to store the receipt object. You can use the receipt to determine if the subscription it represents is valid.

I'm using CargoBay (https://github.com/mattt/CargoBay) to help with StoreKit processing. It has a method:

[[CargoBay sharedManager] verifyTransaction:transaction password:nil success:^(NSDictionary *receipt) {
  NSLog(@"Receipt: %@", receipt);
} failure:^(NSError *error) {
    NSLog(@"Error %d (%@)", [error code], [error localizedDescription]);
}];

Upvotes: 2

Related Questions