iOS Question B4i Restoring non-consumable purchases

Discussion in 'iOS Questions' started by jai, Apr 10, 2015.

  1. jai

    jai Member Licensed User

    Need help with Restoring non-consumable purchases. I can’t restore purchases or obtain related information. Here is how I am testing it-

    1. Purchase an item in Sandbox Environment and get its confirmation. All items associated with this purchase now work fine.

    2. Delete the app

    3. Reinstall it

    4. At some point in the app it tries to restore any prior purchases with –

    MyStore.RestoreTransactions
    This raises-

    Sub MyStore_TransactionsRestored (Success AsBoolean)
    And returns Success as True

    BUT
    Sub MyStore_PurchaseCompleted (Success AsBoolean, Product AsPurchase)

    is not raised and thus no information of past purchases is returned

    5. If I try to purchase this item again it lets me purchase it again saying-
    You’ve Already Purchased This Subscription. Tap Buy to renew or extend it.
    In this Sandbox Environment I get the choice to Cancel or Buy.


    Cancel takes me out of purchasing and Buy lets me buys it again.
    Either way I don’t get any info on the earlier purchase(s).

    How do I get the Product. ProductIdentifier and Product. TransactionDate of past purchases?

    Note that the non-consumable item in this case is a non-renewing subscription.
     
    Last edited: Apr 10, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Does it work if the product is not subscription based?
     
  3. jai

    jai Member Licensed User

    Yes. PurchaseCompleted is raised by RestoreTransactions for a regular non-consumable product.

    To make sure, I created a new test product that is non-consumable and is not subscription. It worked just as you describe in your In-app purchase write up. Purchase details are obtained as Product.ProductIdentifier when
    PurchaseCompleted (Success AsBoolean, Product AsPurchase)
    is raised by
    MyStore.RestoreTransactions

    I need this to work for non-renewing subscription.
     
    valentino s likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. jai

    jai Member Licensed User

    I am using non-renewing subscription.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    valentino s likes this.
  7. jai

    jai Member Licensed User

    In such a case a viable alternative would be to save the purchase receipt in users iCloud account at the time of purchase (in addition to saving it on the device) and then look there for future validations and restorations? Can you please give a sample code how this can be accomplished with B4i? Or, if there may be another practical way to sell a feature of the app for limited time and be able to restore it on all user's devices.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Seems to me that you will need to implement a server side solution to manage the subscriptions.

    If you like to base it on iCloud then you can save the files in DirDocuments and they will automatically be backed up. However they will not be synced automatically on different devices.
     
  9. jai

    jai Member Licensed User

    There is no other server associated with this app, so iCloud is the only thing available to try to work out with. The link
    https://developer.apple.com/library....html#//apple_ref/doc/uid/TP40008267-CH5-SW16

    describes (below) a way to save a receipt in User Default or iCloud. Perhaps this receipt can also be verified from user's other devices. How can this be done in B4i?


    Persisting a Receipt in User Defaults or iCloud
    To store a transaction’s receipt in User Defaults or iCloud, set the value for a key to the data of that receipt.

    #if USE_ICLOUD_STORAGE
    NSUbiquitousKeyValueStore *storage = [NSUbiquitousKeyValueStore defaultStore];
    #else
    NSUserDefaults *storage = [NSUserDefaults standardUserDefaults];
    #endif
    NSData *newReceipt = transaction.transactionReceipt;
    NSArray *savedReceipts = [storage arrayForKey:mad:"receipts"];
    if (!receipts) {
    // Storing the first receipt
    [storage setObject:mad:[newReceipt] forKey:mad:"receipts"];
    } else {
    // Adding another receipt
    NSArray *updatedReceipts = [savedReceipts arrayByAddingObject:newReceipt];
    [storage setObject:updatedReceipts forKey:mad:"receipts"];
    }
    [storage synchronize];
     
  10. jai

    jai Member Licensed User

    How can I programmatically check for and sync or read a DirDocuments file backed up in iCloud from another device of the user?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Currently there is no library that supports iCloud storage (other than the automatic backup).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice