Skip to content

Commit

Permalink
refactor : ThirdParty app open logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kjh5833 committed Mar 5, 2021
1 parent 96bd4ff commit e852fd8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
24 changes: 14 additions & 10 deletions iamport-ios/Classes/Domain/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -136,9 +140,9 @@ class Utils {
return false
}

/**
* 결제 끝났는지 여부
*/
/**
* 결제 끝났는지 여부
*/
static func isPaymentOver(_ uri: URL) -> Bool {
return uri.absoluteString.contains(CONST.IAMPORT_DETECT_URL)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
7 changes: 4 additions & 3 deletions iamport-ios/Classes/Presentation/IamportSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ 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 가 동작할 시나리오
// 취소? 타임아웃 연장? 그대로 진행? ... 등
// 어차피 앱 재설치시, 다시 차이 결제 페이지로 진입할 방법이 없음
if (!result) {
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)
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions iamport-ios/Classes/Presentation/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,22 @@ 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 {
sdkFinish(nil)
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) // 걍 열엇
}
}
}
Expand Down

0 comments on commit e852fd8

Please sign in to comment.