expo-duooomi-app/docs/IAP_TROUBLESHOOTING.md

174 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# iOS IAP 商品拉取失败排查指南
## 问题现象
```
Products fetched successfully----------- undefined
products---------- []
```
## 常见原因和解决方案
### 1. ⚠️ App Store Connect 配置问题
#### 检查商品状态
1. 登录 [App Store Connect](https://appstoreconnect.apple.com)
2. 进入 **我的 App** → 选择你的应用
3. 点击 **功能****App 内购买项目**
4. 确认以下商品存在且状态为 **"准备提交"** 或 **"已批准"**
- `coin_500`
- `coin_1000`
- `coin_2500`
- `coin_5000`
#### 商品类型必须是
- **消耗型项目 (Consumable)** - 用于可重复购买的商品(如算力点数)
### 2. ⚠️ Bundle ID 不匹配
**当前配置:**
```javascript
// app.config.js
bundleIdentifier: 'com.duomi.duooomi.ios'
```
**必须确保:**
- App Store Connect 中的 Bundle ID 与此完全一致
- 不能有大小写差异
- 不能有额外的后缀
### 3. ⚠️ 合约和税务未完成
**App Store Connect****协议、税务和银行业务**
- ✅ 付费 App 协议必须已签署
- ✅ 银行信息必须已填写
- ✅ 税务信息必须已完成
- ✅ 状态显示为**绿色对勾**
### 4. ⚠️ 测试环境配置
#### 沙盒测试账户
1. 前往 **App Store Connect****用户和访问****沙盒技术测试员**
2. 创建测试账户(不能使用真实 Apple ID
3. 在 iOS 设备上:
- **设置** → **App Store****沙盒账户**
- 登录测试账户
#### 设备配置
- 确保设备已登出真实 Apple ID在沙盒测试环境下
- 或使用 TestFlight 构建版本测试
### 5. ⚠️ 代码配置问题
#### 商品类型错误
```typescript
// ❌ 错误
fetchProducts({ skus: ['coin_500'], type: 'all' })
// ✅ 正确(消耗型商品)
fetchProducts({
skus: RECHARGE_OPTIONS.map(o => o.id),
type: 'in-app' // iOS 消耗型商品
})
```
### 6. ⚠️ 构建配置问题
#### 必须使用正式构建
- ❌ Expo Go **不支持** IAP
- ❌ 本地开发构建可能无法连接 App Store
- ✅ 必须使用 **Development Build****TestFlight** 构建
#### 构建命令
```bash
# 开发构建(支持 IAP
bun run build:development:ios
# 或使用 TestFlight
bun run build:test:ios
```
### 7. ⚠️ Expo IAP 版本兼容性
#### 检查版本
```json
// package.json
"expo-iap": "^3.4.8"
```
#### 确保依赖正确
```bash
bunx expo install expo-iap
```
## 调试步骤
### 1. 查看详细日志
```typescript
useEffect(() => {
if (connected) {
console.log('🔍 Fetching SKUs:', skus)
fetchProducts({ skus, type: 'in-app' })
.then((result) => {
console.log('✅ Result:', result)
console.log('📦 Products:', result?.products)
console.log('📊 Count:', result?.products?.length)
})
.catch((error) => {
console.error('❌ Error:', error)
console.error('Code:', error?.code)
console.error('Message:', error?.message)
})
}
}, [connected])
```
### 2. 验证 SKU
**App Store Connect** 中复制准确的产品 ID确保
- 没有空格
- 大小写完全匹配
- 没有特殊字符
### 3. 测试单个商品
```typescript
// 先测试单个已知存在的商品
fetchProducts({ skus: ['coin_500'], type: 'in-app' })
```
## 常见错误代码
| 错误码 | 含义 | 解决方法 |
|--------|------|----------|
| `undefined` | 未连接到 App Store | 检查网络、沙盒账户 |
| `E_NOT_CONFIGURED` | IAP 未配置 | 完成合约和银行信息 |
| `E_UNKNOWN` | 未知错误 | 检查 Bundle ID 和商品状态 |
| `[]` (空数组) | 商品不存在 | 检查 SKU 和商品状态 |
## 快速检查清单
- [ ] App Store Connect 中商品状态为"准备提交"
- [ ] Bundle ID 完全匹配
- [ ] 合约、税务、银行信息已完成
- [ ] 使用沙盒测试账户登录
- [ ] 使用 Development Build 或 TestFlight
- [ ] SKU 名称完全正确(无空格、大小写匹配)
- [ ] 商品类型设置为"消耗型项目"
- [ ] 代码中 `type: 'in-app'`(不是 'all'
## 验证命令
```bash
# 重新构建并测试
bunx expo prebuild --clean
bun run build:development:ios
# 查看构建信息
eas build:list --platform ios
```
## 参考链接
- [Expo IAP 文档](https://docs.expo.dev/versions/latest/sdk/in-app-purchases/)
- [App Store Connect](https://appstoreconnect.apple.com)
- [Apple IAP 测试指南](https://developer.apple.com/documentation/storekit/in-app_purchase/testing_in-app_purchases)