Clearing purchases from iOS in-app purchase sandbox for a test user

前端 未结 8 883
臣服心动
臣服心动 2020-12-02 07:18

Does anyone have any ideas on how to reset and/or clear the iOS in-app purchase sandbox?

I have an app that I\'m testing with the sandbox, and I\'d like to test new

相关标签:
8条回答
  • 2020-12-02 07:50

    I have 2 in app purchase items. 1 for production. and the other for testing. when I need to "clear" I delete the in app item and create new one (15 seconds in itunes connect and 1 second to change the product id in code)

    if i dont need to test "new user", i use the production in app item.

    0 讨论(0)
  • 2020-12-02 07:53

    Well, technically you don't need that.

    If you get SKPaymentTransactionStateRestored, it is 100% equivalent to the app store verifying the user and granting him the purchase. I have a switch like:

    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
    {
      for( SKPaymentTransaction *purch in transactions )
      {
        switch( purch.transactionState )
        {
          case SKPaymentTransactionStateRestored:
            info( "PURCHASE RESTORE" ) ;
            // fall thru
          case SKPaymentTransactionStatePurchased:
            [[SKPaymentQueue defaultQueue] finishTransaction:purch];
            // Do regular changes to app state for this purchase,
            // register in keychain, etc.
            break ;
    
           //.. other cases
         }
      }
    }
    

    The question of having your app logic / take back the purchase is simple: if you're caching purchases in keychain, delete your keychain. If you're doing it some other how, just change your local app state to pretend like the user never purchased it before. The request to purchase dialog is still exactly the same, the only difference is when you punch YES, it gives you SKPaymentTransactionStateRestored instead of SKPaymentTransactionStatePurchased.

    0 讨论(0)
  • 2020-12-02 07:54

    alternatively to create multiple test user solution you can create multiple test in app purchases in iTunes connect then you don't need to change a user account.

    0 讨论(0)
  • 2020-12-02 08:00

    Check out SimStoreKit. It's a "simulated version of the iPhone's StoreKit, for testing store UIs on the iPhone Simulator, or even on device without having to set up IAP in Connect."

    SimStoreKit stores purchases in the user defaults under the key ILSimSKTransactions. So to clear all purchases you can do:

    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"ILSimSKTransactions"]
    

    On the simulator, you can simply remove your app and install it again.

    I've successfully used SimStoreKit to debug my app's store front before testing with the sandbox. The beauty of this library is that it can be set-up to use the same class names as the real StoreKit framework (by doing #define ILSimReplaceRealStoreKit 1 before doing #include <ILSimStoreKit.h>).

    In source files where I need to access StoreKit, I include this header file:

    #import <TargetConditionals.h>
    
    #if TARGET_IPHONE_SIMULATOR
        #define kILSimAllowSimulatedStoreKit 1
        #define ILSimReplaceRealStoreKit 1
        #import <ILSimStoreKit.h>
    #else
        #import <StoreKit/StoreKit.h>
    #endif
    

    This has the effect of using SimStoreKit when I run on the simulator and the real StoreKit when I run on the device.

    0 讨论(0)
  • 2020-12-02 08:03

    Deleting your app and reinstalling works also for sandbox testing. Depends on the app obviously, but I'm testing a subscription based app that only purchases during sign up at the moment so it's been the easiest solution.

    0 讨论(0)
  • 2020-12-02 08:06

    You can't do this, as far as I know. The sandbox backend works like a real account-- once it's purchased, it's purchased (and thus you can test restore). You should do most of your development with the store stuff shimmed out, and then when you get to testing it for real, just expect to create several test accounts.

    0 讨论(0)
提交回复
热议问题