Using RMStore library to get originalAppVersion

1.4k views Asked by At

I have an iOS 7 only product and I want to read the App Store Receipt and check the original app purchase date. I've been using the RMStore library (https://github.com/robotmedia/RMStore) to read the app receipt and return that information, like this:

RMAppReceipt* appReceipt;

appReceipt = [RMAppReceipt bundleReceipt];
if (appReceipt == nil)
{
    NSLog(@"ERROR! NO APP RECEIPT FOUND");
}
else
{    
    NSLog(@"app receipt original version = %@", appReceipt.originalAppVersion);
}

NOTE: I'm not currently using any other part of the RMStore library

In most cases, this works great. The problem is that for a few of my users, appReceipt.originalAppVersion is an empty string. Other fields, like the current appVersion, are fine. After doing a SKReceiptRefreshRequest, still no luck. In fact, the SKReceiptRefreshRequest sometimes makes a good situation worse by changing appReceipt.originalAppVersion from a valid string to an empty string.

For my customers who ran into this problem, I've instructed them to delete the app and redownload it from the app store. In most cases, this does clear up the problem but not always. Obviously I want to prevent the problem without requiring my users to reinstall.

The entire app store receipt functionality is very obfuscated to me and I'm ignorant of all the encryption and decryption going on, and that is why I was hoping to rely on RMStore to do this work for me. I want a nice small local library to do the work without going to a server, and RMStore fits the bill.

I don't know if this is a bug in the RMStore library, or some inherent quirk of the app store receipt system in which there might be a workaround. Has anyone else using RMStore run into this problem of an empty appReceipt.originalAppVersion?

====== Update: Upon further investigation, this seems to be a quirk in how the StoreKit works. I've duplicated the problem with another library, DHAppleReceiptParser. When the problem situation arises, the apple server doesn't seem to be returning the original app version number, so the libraries don't pick it up. However, another undocumented field comes back, original_purchase_date (which is only documented for in app purchase receipts, not the app receipt). I was able to query the iTunes server (buy.itunes.apple.com/verifyReceipt) for verification directly, which is useful for debugging but not recommended for a shipping product. These are the results:

Problem situation. This happens to about 1% of my customers, or quite often after doing a SKReceiptRefreshRequest. There is no "original_application_version" field!

{
environment = Production;
receipt =     {
    "adam_id" = 316120800;
    "application_version" = "6.0.1";
    "bundle_id" = "com.yourcompany.myappid";
    "download_id" = 9999;
    "in_app" =         (
    );
    "original_purchase_date" = "2010-11-26 16:35:57 Etc/GMT";
    "original_purchase_date_ms" = 1290789357000;
    "original_purchase_date_pst" = "2010-11-26 08:35:57 America/Los_Angeles";
    "receipt_type" = Production;
    "request_date" = "2013-12-20 19:35:02 Etc/GMT";
    "request_date_ms" = 1387568102285;
    "request_date_pst" = "2013-12-20 11:35:02 America/Los_Angeles";
};
status = 0;
}

After deleting the app, and doing a fresh install from iCloud purchases. "original_application_version" is there now!

{
    environment = Production;
    receipt =     {
        "adam_id" = 316120800;
        "application_version" = "6.0.1";
        "bundle_id" = "com.yourcompany.myappid";
        "download_id" = 23007878277739;
        "in_app" =         (
        );
        "original_application_version" = "3.1";
        "original_purchase_date" = "2010-11-26 16:35:57 Etc/GMT";
        "original_purchase_date_ms" = 1290789357000;
        "original_purchase_date_pst" = "2010-11-26 08:35:57 America/Los_Angeles";
        "receipt_type" = Production;
        "request_date" = "2013-12-20 21:02:30 Etc/GMT";
        "request_date_ms" = 1387573350752;
        "request_date_pst" = "2013-12-20 13:02:30 America/Los_Angeles";
    };
    status = 0;
}

"original_purchase_date" seems to be more reliable for checking when a product was purchased, but the Apple docs don't mention it for the basic app receipt (only IAP).

0

There are 0 answers