iosobjective-ccocoa-touchapp-storermstore

What's the correct way to use RMStore to get the original purchase date of an app?


I'm releasing an updated version of my app, and I'm transitioning from paid to freemium. To give existing users an ad-free experience, I'm looking to track when they've originally purchased the app.

I'm looking into RMStore, but it's not clear to me how to test reading the original purchase date out of the receipt. I've come up with some simple code which I think should work, but I don't have a good way to test it.

[[RMStore defaultStore] refreshReceiptOnSuccess:^{

    NSURL *url = [RMStore receiptURL];

    NSData *data = [NSData dataWithContentsOfURL:url];

    RMAppReceipt* r =[[RMAppReceipt alloc] initWithASN1Data:data];

    // Cheap and easy conversion to a float...
    //  IRL do a real comparison with the strings...

    if ([[r originalAppVersion] floatValue] < 2.0)
    {
        //  Do something for early-adopters
    }

} failure:^(NSError *error) {
    // Ruh-roh!
}];

I have two issues:

  1. I don't have a valid receipt. What's the procedure for getting one? Do I need an app bundle ID that's already live? Are there test receipts somewhere?

  2. If I want to base the logic on dates instead of version numbers, can I do that? There's no originalPurchaseDate property on RMAppReciept. (I did file an issue on GitHub.)


Solution

  • What's the correct way to use RMStore to get the original purchase date of an app?

    There is no such information in the receipt. You can get the purchase date of in-app purchases, though. RMStore helps you with this via the RMAppReceiptIAP object.

    To give existing users an ad-free experience, I'm looking to track when they've originally purchased the app.

    As suggested by @sergio, you can read the original app version from the app receipt. Bear in mind that receipts are only available in iOS 7.

    I don't have a valid receipt. What's the procedure for getting one? Do I need an app bundle ID that's already live? Are there test receipts somewhere?

    Apps in sandbox environment will have a test receipt, but you can't manipulate its fields.

    As an alternative, you can configure RMAppReceipt or mock it to test your various workflows.

    If I want to base the logic on dates instead of version numbers, can I do that? There's no originalPurchaseDate property on RMAppReceipt.

    Not with the app receipt, as there is no such field at app level.

    BTW, avoid refreshing the receipt on startup as it tends to show the Apple ID password prompt. Only refresh if you don't find the receipt or if the info is missing.