-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK crashes for Pre-approval & Recurring type, when payment UI is not…
… loaded fully (#16) * Add missing images and changed default mid on demoapp * Add handling of waiting for payment UI * Bump versions Co-authored-by: Thisura98 <[email protected]>
- Loading branch information
1 parent
4b1b63a
commit 7e3b0e0
Showing
10 changed files
with
181 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// WaitUntil.swift | ||
// payHereSDK | ||
// | ||
// Created by Thisura Dodangoda on 2022-05-17. | ||
// Copyright © 2022 PayHere. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
Wait until a condition is true to execute a handler | ||
*/ | ||
internal class WaitUntil{ | ||
|
||
private let condition: (() -> Bool)! | ||
private let completion: (() -> Void)! | ||
private let timeout: TimeInterval! | ||
|
||
init( | ||
condition: @escaping () -> Bool, | ||
onCompletion: @escaping () -> Void, | ||
timeout: TimeInterval = 5.0 | ||
){ | ||
self.condition = condition | ||
self.completion = onCompletion | ||
self.timeout = timeout | ||
|
||
run() | ||
} | ||
|
||
private func run(){ | ||
guard !condition() else { | ||
completion() | ||
return | ||
} | ||
|
||
DispatchQueue.global().async { [weak self] in | ||
guard let `self` = self else { return } | ||
|
||
let start = Date().timeIntervalSince1970 | ||
var shouldBreak = false | ||
var isTimeout = false | ||
|
||
while(!shouldBreak){ | ||
usleep(80000) | ||
|
||
DispatchQueue.main.async { | ||
if self.condition(){ | ||
shouldBreak = true | ||
} | ||
} | ||
|
||
if ((Date().timeIntervalSince1970 - start) > self.timeout){ | ||
shouldBreak = true | ||
isTimeout = true | ||
} | ||
} | ||
|
||
guard !isTimeout else { return } | ||
|
||
DispatchQueue.main.async { | ||
self.completion() | ||
} | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
payHereSDK/Sources/image.xcassets/warning.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "warning.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.