Skip to content

Commit

Permalink
Merge pull request #97 from xendit/release/3.10.4
Browse files Browse the repository at this point in the history
Fix memory leak on WebViewController
  • Loading branch information
ahmadAlfhajri authored Jan 6, 2025
2 parents 2bb03b3 + d346e48 commit 4ca720e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Note that starting version 3.10.0, it requires minimum version of iOS 11. If you
Add this to your Podfile.

```ruby
pod 'Xendit', '~> 3.10.3'
pod 'Xendit', '~> 3.10.4'
```

**Important:** Import SDK in Objective-C project with CocoaPods integration, you can do as following
Expand Down
2 changes: 1 addition & 1 deletion Sources/Xendit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.10.3</string>
<string>3.10.4</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class AuthenticationWebViewController: UIViewController, WKScriptMessageHandler,

webView = WKWebView(frame: view.frame, configuration: webConfiguration)
webView.navigationDelegate = self
webView.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(webView)

Expand Down Expand Up @@ -134,4 +135,14 @@ class AuthenticationWebViewController: UIViewController, WKScriptMessageHandler,
Log.shared.verbose("web auth: navigation error \(error)")
authenticateCompletion(nil, XenditError(errorCode: "WEBVIEW_ERROR", message: error.localizedDescription))
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Remove script message handler
webView.configuration.userContentController.removeAllUserScripts()
webView.configuration.userContentController.removeScriptMessageHandler(forName: "callbackHandler")
// Clear any other references
webView.navigationDelegate = nil
webView = nil
}
}
11 changes: 11 additions & 0 deletions Sources/Xendit/WebViewController/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class WebViewController: UIViewController, WKScriptMessageHandler, WKNavigationD
webConfiguration.userContentController = contentController
webView = WKWebView(frame: view.frame, configuration: webConfiguration)
webView.navigationDelegate = self
webView.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(webView)
NSLayoutConstraint.activate([
Expand Down Expand Up @@ -139,4 +140,14 @@ class WebViewController: UIViewController, WKScriptMessageHandler, WKNavigationD
Log.shared.verbose("web auth: navigation error \(error)")
authenticateCompletion(nil, XenditError(errorCode: "WEBVIEW_ERROR", message: error.localizedDescription))
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Remove script message handler
webView.configuration.userContentController.removeAllUserScripts()
webView.configuration.userContentController.removeScriptMessageHandler(forName: "callbackHandler")
// Clear any other references
webView.navigationDelegate = nil
webView = nil
}
}
2 changes: 1 addition & 1 deletion Sources/Xendit/XDTApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class XDTApiClient {
internal static let CLIENT_TYPE = "SDK";
internal static let CLIENT_API_VERSION = "2.0.0";
internal static let CLIENT_IDENTIFIER = "Xendit iOS SDK";
internal static let CLIENT_SDK_VERSION = "3.10.3";
internal static let CLIENT_SDK_VERSION = "3.10.4";

private static let WEBAPI_FLEX_BASE_URL = "https://sandbox.webapi.visa.com"

Expand Down
2 changes: 1 addition & 1 deletion Xendit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Xendit'
s.version = '3.10.3'
s.version = '3.10.4'
s.license = 'MIT'
s.homepage = 'https://www.xendit.co'
s.author = { 'Juan Gonzalez’' => '[email protected]' }
Expand Down

0 comments on commit 4ca720e

Please sign in to comment.