iosobjective-cin-app-purchasermstore

Get IAP original purchase date?


I'm wondering if there's any way to get to the original purchase date of a consumable, non-recurring in-app purchase. The IAP's in my app are valid for 3 months. However, when a user deletes the app and then restores his purchase I can't find any way to get the original purchase date to see if the 3 months have passed. Any ideas?

[[RMStore defaultStore] restoreTransactionsOnSuccess:^(NSArray *transactions) {
    [[Game user] boughtFish];
    NSLog(@"Transactions restored");
} failure:^(NSError *error) {
    NSLog(@"Something went wrong");
}];

Solution

  • I looked into the documentation and source code.

    The success block of restoreTransactionsOnSuccess takes an array of transactions.
    It comes naturally to the curious mind to ask for its reason for being.

    It is easily found that the array is filled with objects of type SKPaymentTransaction

    One nice property of such class is transactionDate of type NSDate, which is what you want.


    A simple proof of concept[compilation and test needed] is here

    [[RMStore defaultStore] restoreTransactionsOnSuccess:^(NSArray* transactions) 
    {
        NSLocale* dateLocale = [NSLocale autoupdatingCurrentLocale];
    
        for (SKPaymentTransaction* t in transactions)
            NSLog(@"%@", [t.transactionDate descriptionWithLocale: dateLocale]); 
    } 
    failure:^(NSError* error) 
    {
    
    }];