Sometimes, even creating the perfect app and acquiring users is not enough. The “last mile” issues can rob you of your potential revenue, one of them being iOS errors like
SKErrorDomain Error 2. It’s more common than you might think — so common, in fact, that we decided to write a short guide about it.
Here, we’re going to dive deep into what this error is all about. We’ll also share some foolproof solutions to help you fix it in no time. The goal is to enhance your app’s reliability, boost user satisfaction, and eliminate any revenue drainers. Let’s get started.
What is SKErrorDomain Code=2
According to the Apple Developer site, SKError 2 is also known as
SKError.paymentCancelled. It occurs when a person gets to the payment pop-up (that is, is asked to confirm a purchase or a subscription), and then declines it. Technically, it’s not an error, as the cancellation is triggered by the user: even though, of course, we’d like the process to be as smooth as possible.
This error can also pop up regardless of user actions and be caused by an outside factor, and this article covers explicitly such cases.
What can cause SKErrorDomain Code=2
There are several potential triggers for this confounding error, the main two being network issues and StoreKit configurations. Putting it in layman’s terms, the error is mainly caused either by problems in communication between the user, the app, and the Store, or no communication at all.
Network issues can be a significant catalyst for the
SKErrorDomain Code=2. This is because the StoreKit framework heavily relies on consistent network connectivity with little to no lag to perform transactions effectively. Unstable or unreliable connections — for example, using a hotspot or a free VPN — can interfere with the transmission of data.
The StoreKit framework is the core engine driving your in-app transactions, and any mistake in this setup can readily lead to the
SKErrorDomain Code=2 error. An incorrectly defined product ID, for example, can trigger the error. Product IDs should match precisely with those defined in App Store Connect; any discrepancy can create conflicts, leading to transaction failures. Moreover, if a transaction is not correctly processed, finalized, or saved in your app, StoreKit might misinterpret the state, resulting in this error.
How to troubleshoot SKErrorDomain Error 2
Once you’ve run into the issue, it makes sense to go through every detail of the process to make sure everything is good on your part. For
SKErrorDomain Error 2, the process is mostly the same for the sandbox and product environments, with a couple of minor differences.
Here’s what you should do while in the sandbox environment:
- Review StoreKit configuration. Begin by checking your app’s StoreKit configuration. Ensure all product IDs in your code match the ones set in App Store Connect. Misconfigured or mismatched IDs often result in errors in the sandbox environment.
- Examine transaction handling. StoreKit handles a sequence of states for each transaction. Each state requires specific handling in your code, and proper handling of these states can eliminate errors. Review your transaction handling code for completeness and accuracy.
- Ensure you’re finishing transactions upon success/failure. As we’ve explained before, the general cause of the error occurs at ‘the last mile’. Make sure each payment, even a canceled one, finishes ‘properly’ in your code.
- Test network stability. Although it’s a sandbox environment, network conditions still matter. Verify that your testing device has a stable and strong internet connection.
- Use Apple’s StoreKit testing tools. Apple provides specific tools to test StoreKit locally in Xcode and the sandbox. These tools allow you to simulate transactions, helping you to identify potential errors.
- Check OS and app versions. We know this one is obvious, but still: make sure the app and iOS versions are up-to-date. Each new iOS update, even a minor one, brings some new terms and rules to the StoreKit, so you would benefit from having the latest one.
With real-life scenarios, you get some extra steps — and extra sources of information.
- Monitor user feedback. Users can often provide the first indication of an issue. Pay close attention to app reviews, support requests, and social media channels where users might report problems.
- Analyze error logs. Use your app’s error logging system to gather information about where and when the error occurs. Troubleshooting becomes that much easier where you can pinpoint a specific page or an SKU that causes the problem.
- Make sure the IAP hasn’t been purchased before. One of the key real-life causes reported by the developers occurred when a user tried to purchase an already active subscription. Always have the ‘Restore Purchases’ button at the ready and ask users to try it if they run into any problems.
How to submit a bug report
We’ve already covered this part in our previous article of this cycle about a similar error, Error=0. Here’s the rundown:
- Access either the Feedback Assistant website or its app on your Mac.
- Sign in with the Apple ID linked to your Developer Program membership.
- Click the “New Feedback” button.
- Make sure to fill out the feedback form with as much detailed information as you can. The specific error at hand (
SKErrorDomain Error 2), during what process the error occurs, and any important pieces of code or log extracts.
- Attach any relevant screenshots or data, that can provide more context about the problem.
- Once you’ve filled out the form, review your submission for any errors or missing information, then hit “Submit”.
Apple will proceed to examine your feedback.
This may take several days, but it’s often rewarded with a potential resolution.
Get an ebook with insights
and advice from top experts
How to prevent SKErrorDomain Code=2
Implementing preventive measures and following best practices can significantly reduce the likelihood of encountering the
SKErrorDomain Code=2 error in future projects. Here are some strategies to consider:
- Test StoreKit configuration. Test your StoreKit configuration before deploying your app. Make sure that all product IDs match those in App Store Connect and that all transactions process correctly during testing.
- Handle transactions. Ensure that your code accounts for all possible transaction states. Since
SKErrorDomain Code=2has to do with a ‘canceled’ purchase, make sure your app finishes every transaction.
- Implement an error logging system. A comprehensive error logging system can help you identify and address issues promptly. By tracking exactly what product or purchase step the errors occur on, you’ll greatly simplify the troubleshooting process.
- Regularly review user feedback. Stay on top of user reviews and feedback. Users are often the first to spot issues, and their feedback can help you identify and resolve problems early. Don’t shy away from asking for screenshots or engaging with users on social media.
- Regularly update your app and iOS version. Update your application and ensure it’s compatible with the latest iOS versions. Compatibility issues with newer OS versions can often lead to unexpected errors.
With these practices in your development process, you can significantly reduce the risk of encountering the
SKErrorDomain Code=2 error and ensure a smoother user experience.
Effectively managing the
SKErrorDomain Code=2 error is a critical aspect of maintaining a robust and user-friendly iOS application. This error can disrupt in-app transactions, potentially leading to a diminished user experience and even revenue loss. Luckily, it’s a minor mistake that can be easily tracked and resolved.
A seamless user experience is the cornerstone of any successful app, and ensuring error-free transactions is an integral part of this. With the insights shared in this article, you’re now well-equipped to manage the
SKErrorDomain Code=2, contributing to a more robust and reliable app that users can truly appreciate.