(iOS + StoreKit) Can I detect when I'm in the sandbox?
After a bit of digging I found this from Apple's Technical Note TN2259:
How do I verify my receipt (iOS)?
Always verify your receipt first with the production URL; proceed to verify with the sandbox URL if you receive a 21007 status code. Following this approach ensures that you do not have to switch between URLs while your application is being tested or reviewed in the sandbox or is live in the App Store.
So it looks like I should axe the &sandbox
parameter completely and just do that. I really had to dig for this answer so I'm posting it here in hopes that someone else runs across it!
How do I know if an in-app-purchase receipt comes from the sandbox?
When you verify the receipt, if you receive a status code 21007 it means its a sandbox receipt. Look here: https://developer.apple.com/library/content/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-RECEIPTURL
What url should I use to verify my receipt?
Always verify your receipt first with the production URL; proceed to verify with the sandbox URL if you receive a 21007 status code. Following this approach ensures that you do not have to switch between URLs while your application is being tested or reviewed in the sandbox or is live in the App Store.The 21007 status code indicates that this receipt is a sandbox receipt, but it was sent to the production service for verification. A status of 0 indicates that the receipt was properly verified. See WWDC 2012: Managing Subscriptions with In-App Purchase for more information.
Storekit / In App Purchases: Does the Environment: Sandbox tag disappear when I submit my app to the app store?
You don't have to do nothing. This is just indication that you are using sandbox when your app will be submitted for production, reviewed and approved, this notification will not be shown to the users.
Determining if Xcode StoreKit Configuration file is being used
I was just wondering the same, because since I perform local receipt validation, I had to use the right certificate: StoreKit or Apple's root.
The solution is pretty simple: add a new product inside your .storekit file to check if you are using the local config or the sandbox/App Store one.
Add a new product ID called using_store_kit_conf then pass the array of IDs to SKProductsRequest
containing also this one.
When you get the list of products in the delegate, check if the using_store_kit_conf product is present to determine if you're using the StoreKit Configuration file.
If you list all your products to the user, remember to filter out the using_store_kit_conf product.
Sample:
static let premiumOneTime = "premium_one_time"
static let usingStoreKitConfiguration = "using_store_kit_conf"
static let productIds: Set<String> = [InAppPurchase.premiumOneTime, InAppPurchase.usingStoreKitConfiguration]
private var products: [SKProduct] = []
Pass all the IDs:
productsRequest = SKProductsRequest(productIdentifiers: InAppPurchase.productIds)
Delegate:
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
self.products = response.products
print("InAppPurchase products: ", response.products)
}
Check if using StoreKit Configuration:
var isUsingStoreKitConfiguration: Bool {
products.contains(where: { product in product.productIdentifier == InAppPurchase.usingStoreKitConfiguration })
}
NOTE: This only works after you have loaded the products list, otherwise isUsingStoreKitConfiguration
will always return false.
When to switch from Sandbox to production StoreKit server?
I found an answer on the StoreKit FAQ:
What url should I use to verify my receipt (iOS)?
Use the sandbox URL https://sandbox.itunes.apple.com/verifyReceipt while testing your application in the sandbox and while your application is in review.
Use the production URL http://buy.itunes.apple.com/verifyReceipt once your application is live in the App Store.
The only thing I still don't understand is, what if I am not at my computer the moment the app goes live to make the switch?
Related Topics
Where Is the Official Documentation for Cvopenglestexture Method Types
Coreanimation - Opacity Fade in and Out Animation Not Working
Swift: Equivalent Objective-C Runtime Class
How to Use Coreaudio's Audioconverter to Encode Aac in Real-Time
Storyboard Navigation Controller and Tab Bar Controller
Swiftui Transitions: Scale from Some Frame - Like iOS Homescreen Is Doing When Opening an App
How to Test for the Class of a Variable in Swift
Is There a Practical Way to Compress Nsdata
Firinstanceid/Warning Stop!! Will Reset Deviceid from Memory [Xcode:Console Log]
How to Install the "App Store" in an iOS Simulator
How to Animate Uitableviewcell Height Using Auto-Layout
How to Reset the Application Data After Each Test with Xcode 7 UI Testing
Gem Native Extension Error While Installing Cocoapods
Skmutablepayment Property: Applicationusername
Delete a Device from My Developer Account to Increase the Count