From e852fd800a5399fd22189740f54043561ee3efb2 Mon Sep 17 00:00:00 2001 From: bingbong Date: Fri, 5 Mar 2021 15:21:50 +0900 Subject: [PATCH] refactor : ThirdParty app open logic --- iamport-ios/Classes/Domain/Utils/Utils.swift | 24 +++++++++++-------- .../CertificationWebViewStrategy.swift | 13 ---------- .../Classes/Presentation/IamportSdk.swift | 7 +++--- .../Presentation/WebViewController.swift | 11 ++++----- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/iamport-ios/Classes/Domain/Utils/Utils.swift b/iamport-ios/Classes/Domain/Utils/Utils.swift index 1cb9bfa..dda47ee 100644 --- a/iamport-ios/Classes/Domain/Utils/Utils.swift +++ b/iamport-ios/Classes/Domain/Utils/Utils.swift @@ -112,17 +112,21 @@ class Utils { return nil } - static func openApp(_ url: URL) -> Bool { - let application = UIApplication.shared - let result = application.canOpenURL(url) - - if (result) { + static func justOpenApp(_ url: URL) { + UIApplication.shared.do { app in if #available(iOS 10.0, *) { - application.open(url, options: [:], completionHandler: nil) + app.open(url, options: [:], completionHandler: nil) } else { - application.openURL(url) + app.openURL(url) } } + } + + static func openAppWithCanOpen(_ url: URL) -> Bool { + let result = UIApplication.shared.canOpenURL(url) + if (result) { + justOpenApp(url) + } return result } @@ -136,9 +140,9 @@ class Utils { return false } -/** - * 결제 끝났는지 여부 - */ + /** + * 결제 끝났는지 여부 + */ static func isPaymentOver(_ uri: URL) -> Bool { return uri.absoluteString.contains(CONST.IAMPORT_DETECT_URL) } diff --git a/iamport-ios/Classes/Domain/strategy/CertificationWebViewStrategy.swift b/iamport-ios/Classes/Domain/strategy/CertificationWebViewStrategy.swift index e95ea37..de4ca2d 100644 --- a/iamport-ios/Classes/Domain/strategy/CertificationWebViewStrategy.swift +++ b/iamport-ios/Classes/Domain/strategy/CertificationWebViewStrategy.swift @@ -9,17 +9,4 @@ import RxSwift class CertificationWebViewStrategy: WebViewStrategy { - override func onUpdatedUrl(url: URL) { - dlog("CertificationWebViewStrategy onUpdatedUrl \(url)") - if (Utils.isAppUrl(url)) { - print("isAppUrl") - RxBus.shared.post(event: EventBus.WebViewEvents.ThirdPartyUri(thirdPartyUri: url)) - return - } - } - - override func doWork(_ payment: Payment) { - super.doWork(payment) - } - } diff --git a/iamport-ios/Classes/Presentation/IamportSdk.swift b/iamport-ios/Classes/Presentation/IamportSdk.swift index d0cf2fe..88681d1 100644 --- a/iamport-ios/Classes/Presentation/IamportSdk.swift +++ b/iamport-ios/Classes/Presentation/IamportSdk.swift @@ -131,7 +131,7 @@ public class IamportSdk { private func openApp(_ payment: Payment, appAddress: URL) { - let result = Utils.openApp(appAddress) // 앱 열기 + let result = Utils.openAppWithCanOpen(appAddress) // 앱 열기 // TODO openApp result = false 일 떄, 이미 chai strategy 가 동작할 시나리오 // 취소? 타임아웃 연장? 그대로 진행? ... 등 // 어차피 앱 재설치시, 다시 차이 결제 페이지로 진입할 방법이 없음 @@ -139,9 +139,10 @@ public class IamportSdk { if let scheme = appAddress.scheme, let urlString = AppScheme.getAppStoreUrl(scheme: scheme), let url = URL(string: urlString) { - Utils.openApp(url) // 앱스토어 이동 + Utils.justOpenApp(url) // 앱스토어 이동 } else { - sdkFinish(IamPortResponse.makeFail(payment: payment, msg: "지원하지 않는 App Scheme\(String(describing: appAddress.scheme)) 입니다")) +// sdkFinish(IamPortResponse.makeFail(payment: payment, msg: "지원하지 않는 App Scheme \(String(describing: appAddress.scheme)) 입니다")) + Utils.justOpenApp(appAddress) } } } diff --git a/iamport-ios/Classes/Presentation/WebViewController.swift b/iamport-ios/Classes/Presentation/WebViewController.swift index 812f93a..a6d82ac 100644 --- a/iamport-ios/Classes/Presentation/WebViewController.swift +++ b/iamport-ios/Classes/Presentation/WebViewController.swift @@ -301,14 +301,12 @@ class WebViewController: UIViewController, WKUIDelegate { func openThirdPartyApp(_ url: URL) { dlog("openThirdPartyApp \(url)") - let result = Utils.openApp(url) // 앱 열기 + let result = Utils.openAppWithCanOpen(url) // 앱 열기 if (!result) { - if let scheme = url.scheme, let urlString = AppScheme.getAppStoreUrl(scheme: scheme), let url = URL(string: urlString) { - - Utils.openApp(url) // 앱스토어로 이동 + Utils.justOpenApp(url) // 앱스토어로 이동 } else { guard let pay = payment else { @@ -316,8 +314,9 @@ class WebViewController: UIViewController, WKUIDelegate { return } - let response = IamPortResponse.makeFail(payment: pay, msg: "지원하지 않는 App Scheme\(url.scheme) 입니다") - sdkFinish(response) +// let response = IamPortResponse.makeFail(payment: pay, msg: "지원하지 않는 App Scheme \(String(describing: url.scheme)) 입니다") +// sdkFinish(response) + Utils.justOpenApp(url) // 걍 열엇 } } }