From 45b2c336cd421c475009ffe9989323b38119b74e Mon Sep 17 00:00:00 2001 From: JiWoong Sul Date: Mon, 9 Mar 2026 15:45:58 +0900 Subject: [PATCH] =?UTF-8?q?fix(iap):=20=EC=95=B1=20=EC=9E=AC=EC=84=A4?= =?UTF-8?q?=EC=B9=98=20=EC=8B=9C=20=EA=B5=AC=EB=A7=A4=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=20=EB=B3=B5=EC=9B=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 초기화 시 로컬 구매 기록이 없으면 스토어에서 자동 복원 시도 - fire-and-forget 방식으로 초기화 블로킹 없음 - 이미 구매된 상태면 불필요한 스토어 호출 차단 --- lib/src/core/engine/iap_service.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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();