fix(iap): 앱 재설치 시 구매 자동 복원 추가

- 초기화 시 로컬 구매 기록이 없으면 스토어에서 자동 복원 시도
- fire-and-forget 방식으로 초기화 블로킹 없음
- 이미 구매된 상태면 불필요한 스토어 호출 차단
This commit is contained in:
JiWoong Sul
2026-03-09 15:45:58 +09:00
parent b98451919a
commit 45b2c336cd

View File

@@ -123,6 +123,12 @@ class IAPService {
_isInitialized = true;
debugPrint('[IAPService] Initialized');
// 로컬에 구매 기록이 없으면 스토어에서 자동 복원 시도
// (앱 삭제 후 재설치 대응, 비동기로 실행하여 초기화 블로킹 없음)
if (!_adRemovalPurchased) {
_tryAutoRestore();
}
}
/// 상품 정보 로드
@@ -143,6 +149,17 @@ class IAPService {
}
}
/// 앱 시작 시 자동 구매 복원 (재설치 대응)
///
/// purchaseStream 구독 후 호출되므로, 복원된 구매는
/// _onPurchaseUpdate → _handleSuccessfulPurchase로 처리됨.
void _tryAutoRestore() {
debugPrint('[IAPService] Attempting auto-restore...');
_iap.restorePurchases().catchError((Object error) {
debugPrint('[IAPService] Auto-restore failed: $error');
});
}
/// 저장된 구매 상태 로드
Future<void> _loadPurchaseState() async {
final prefs = await SharedPreferences.getInstance();