diff --git a/lib/src/core/engine/iap_service.dart b/lib/src/core/engine/iap_service.dart index 61d6e4a..651a4f8 100644 --- a/lib/src/core/engine/iap_service.dart +++ b/lib/src/core/engine/iap_service.dart @@ -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 _loadPurchaseState() async { final prefs = await SharedPreferences.getInstance();