1

I know I have configured my app (for iOS 7) correctly for the sandbox environment because I can make a test purchase, and I see the alert with the [Environment: Sandbox] text when the test purchase goes through. The receipt is refreshed at the same time and I can access it using the +[NSBundle appStoreReceiptURL] method.

But whenever I try to refresh the receipt using the methods in the SKReceiptRefreshRequest class alone, I only ever get this sequence:

  1. The “Sign In” alert shows from which I choose “Use Existing Apple ID”.

  2. When the “Apple ID Password” alert appears I enter the test user’s credentials.

  3. But this alert always shows right after entering the credentials:

“This Apple ID has not yet been used in the iTunes Store. Tap review to sign in, then review your account information.”

which of course goes on to ask for credit card information which you shouldn’t have to do in the sandbox environment.

I use this code in the app delegate to initiate the receipt refresh:

// in didFinishLaunchingWithOptions:

SKReceiptRefreshRequest *request = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:nil];
request.delegate = self;
[request start];

// with the delegate methods:

-(void)requestDidFinish:(SKRequest *)request
{
    if ([request isKindOfClass:[SKReceiptRefreshRequest class]]) {
        NSLog(@"Got a new receipt...");
    }
}

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@“%@“, error.description);
}

But the only delegate method called is didFailWithError: which gives the message:

Error Domain=SSServerErrorDomain Code=5001 "Could Not Sign In" UserInfo=0x14d8a780 {NSLocalizedFailureReason=This Apple ID has not yet been used in the iTunes Store., NSLocalizedDescription=Could Not Sign In}

Before trying to refresh the receipt I always:

  1. Delete the app from the device

  2. Make sure Settings->App Store has no entered Apple ID credentials

  3. Sign the app with my developer credentials

  4. Make sure that the test account has had a previous purchase made so that a receipt can be generated.

  5. Make sure that the test account credentials are never entered into the App Store login (because this invalidates them for purposes of testing).

Is it possible to do a receipt refresh in the sandbox?

Update: now working

I finally got it working - but I don’t know exactly what the key step was - other than to be persistent and keep trying.

For the benefit of anyone else with the same problem here are the steps I followed:

  1. Create a brand new test user, but did not make a test purchase on the account.

  2. Deleted the app from the device and made sure no account was logged into Settings->App Store.

  3. I launched the app in Xcode and got the error message in the console that I had been getting all along - with this description text:

"Error Domain=SSServerErrorDomain Code=5001 "Could Not Sign In" UserInfo=0x155f5140 {NSLocalizedFailureReason=This Apple ID has not yet been used in the iTunes Store., NSLocalizedDescription=Could Not Sign In}".

  1. When the "This Apple ID has not yet been used in the iTunes Store." alert came up I pressed the cancel button.

  2. Shut down the app, and making no changes, relaunched it under Xcode. I did not delete the app from the device before relaunching.

  3. This time the “This Apple ID has not yet been used in the iTunes Store.” message did not appear and instead a dialog prompting for an Apple ID and password appeared. I entered the test account credentials into the dialog.

  4. After I entered the test user credentials, the SKRequestDelegate requestDidFinish: delegate method was called, and the receipt was placed in the app bundle. Incidentally, the SKRequest instance supplied by the requestDidFinish: method was of type SKReceiptRefreshRequest.

I found that once it worked for the first time, it kept on working - and I didn’t have to delete the app or clear the credentials from Settings->App Store - the receipt refresh would continue to work in the background, using the test credentials that were from that point on cached in Settings->App Store.

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
rfox
  • 94
  • 2
  • 6
  • Have you looked at http://stackoverflow.com/questions/4566329/expected-sequence-when-using-itunes-test-user – Chris Prince Aug 11 '14 at 14:31
  • Yeah, I think I've read every SO post connected with receipt-refreshing (I've been working on this feature for several weeks) and there's nothing there that I haven't tried. Mind you, most of those posts date from pre-iOS 7 days, and my situation is that I'm trying to only refresh the receipt, not make an actual test purchase. But thanks for bringing that thread to my attention. – rfox Aug 11 '14 at 15:24

0 Answers0