Skip to main content
Version: 14.6

iOS Setup

IapKit - In-App Purchase Validation Service

For complete iOS setup instructions including App Store Connect configuration, Xcode setup, and testing guidelines, please visit:

👉 iOS Setup Guide - openiap.dev

The guide covers:

  • App Store Connect configuration
  • Xcode project setup
  • Sandbox testing
  • Common troubleshooting steps

Code Implementation​

Basic Setup​

import {useIAP, ErrorCode} from 'react-native-iap';

const productIds = [
'com.yourapp.premium',
'com.yourapp.coins_100',
'com.yourapp.subscription_monthly',
];

function App() {
const {connected, products, fetchProducts, requestPurchase, validateReceipt} =
useIAP({
onPurchaseSuccess: (purchase) => {
console.log('Purchase successful:', purchase);
// Handle successful purchase
validatePurchase(purchase);
},
onPurchaseError: (error) => {
console.error('Purchase failed:', error);
// Handle purchase error
},
});

React.useEffect(() => {
if (connected) {
fetchProducts({skus: productIds, type: 'in-app'});
}
}, [connected]);

const validatePurchase = async (purchase) => {
try {
// New platform-specific verification API (v14.6+)
const result = await validateReceipt({
apple: {sku: purchase.productId},
});
if (result.isValid) {
// Grant user the purchased content
console.log('Receipt is valid');
}
} catch (error) {
console.error('Validation failed:', error);
}
};

return (
<View>
{products.map((product) => (
<TouchableOpacity
key={product.id}
onPress={() =>
requestPurchase({
request: {apple: {sku: product.id}},
type: 'in-app',
})
}
>
<Text>
{product.title} - {product.displayPrice}
</Text>
</TouchableOpacity>
))}
</View>
);
}

💡 Cross-Platform Note: This example shows iOS-specific usage with apple.sku. For cross-platform compatibility, include both apple and google fields in your request object. The older ios and android fields are deprecated but still supported. See the Core Methods documentation for details.

Common Issues​

Product IDs Not Found​

Problem: Products return empty or undefined

Solutions:

  1. Check Prerequisites (Most common cause):

    • Verify ALL agreements are signed in App Store Connect > Business
    • Ensure ALL banking, legal, and tax information is completed AND approved by Apple
    • These are the most commonly overlooked requirements
  2. Verify Product Configuration:

    • Product IDs match exactly between code and App Store Connect
    • Products are in "Ready to Submit" or "Approved" state
    • Bundle identifier matches
  3. Use Proper Sandbox Testing:

    • Sign in via Settings > Developer > Sandbox Apple Account
    • NOT through the App Store app

Sandbox Testing Issues​

Problem: "Cannot connect to iTunes Store" error Solution:

  • Use a dedicated sandbox test user
  • Sign out of regular App Store account
  • Verify internet connection
  • Try on a real device (simulator may have issues)

Purchase Verification Failures​

Problem: Receipt validation returns invalid Solution:

  • Check if app is properly signed
  • Verify receipt data is not corrupted
  • Ensure proper error handling for network issues

Best Practices​

  1. Always validate receipts server-side for production apps
  2. Handle all error cases gracefully
  3. Test thoroughly with sandbox users
  4. Provide restore functionality for non-consumable products

Next Steps​