Skip to content

Commit 4ca720e

Browse files
Merge pull request #97 from xendit/release/3.10.4
Fix memory leak on WebViewController
2 parents 2bb03b3 + d346e48 commit 4ca720e

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Note that starting version 3.10.0, it requires minimum version of iOS 11. If you
1919
Add this to your Podfile.
2020

2121
```ruby
22-
pod 'Xendit', '~> 3.10.3'
22+
pod 'Xendit', '~> 3.10.4'
2323
```
2424

2525
**Important:** Import SDK in Objective-C project with CocoaPods integration, you can do as following

Sources/Xendit/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.10.3</string>
18+
<string>3.10.4</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Sources/Xendit/WebViewController/AuthenticationWebviewController.swift

+11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class AuthenticationWebViewController: UIViewController, WKScriptMessageHandler,
7676

7777
webView = WKWebView(frame: view.frame, configuration: webConfiguration)
7878
webView.navigationDelegate = self
79+
webView.translatesAutoresizingMaskIntoConstraints = false
7980

8081
view.addSubview(webView)
8182

@@ -134,4 +135,14 @@ class AuthenticationWebViewController: UIViewController, WKScriptMessageHandler,
134135
Log.shared.verbose("web auth: navigation error \(error)")
135136
authenticateCompletion(nil, XenditError(errorCode: "WEBVIEW_ERROR", message: error.localizedDescription))
136137
}
138+
139+
override func viewWillDisappear(_ animated: Bool) {
140+
super.viewWillDisappear(animated)
141+
// Remove script message handler
142+
webView.configuration.userContentController.removeAllUserScripts()
143+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "callbackHandler")
144+
// Clear any other references
145+
webView.navigationDelegate = nil
146+
webView = nil
147+
}
137148
}

Sources/Xendit/WebViewController/WebViewController.swift

+11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class WebViewController: UIViewController, WKScriptMessageHandler, WKNavigationD
8282
webConfiguration.userContentController = contentController
8383
webView = WKWebView(frame: view.frame, configuration: webConfiguration)
8484
webView.navigationDelegate = self
85+
webView.translatesAutoresizingMaskIntoConstraints = false
8586

8687
view.addSubview(webView)
8788
NSLayoutConstraint.activate([
@@ -139,4 +140,14 @@ class WebViewController: UIViewController, WKScriptMessageHandler, WKNavigationD
139140
Log.shared.verbose("web auth: navigation error \(error)")
140141
authenticateCompletion(nil, XenditError(errorCode: "WEBVIEW_ERROR", message: error.localizedDescription))
141142
}
143+
144+
override func viewWillDisappear(_ animated: Bool) {
145+
super.viewWillDisappear(animated)
146+
// Remove script message handler
147+
webView.configuration.userContentController.removeAllUserScripts()
148+
webView.configuration.userContentController.removeScriptMessageHandler(forName: "callbackHandler")
149+
// Clear any other references
150+
webView.navigationDelegate = nil
151+
webView = nil
152+
}
142153
}

Sources/Xendit/XDTApiClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class XDTApiClient {
3838
internal static let CLIENT_TYPE = "SDK";
3939
internal static let CLIENT_API_VERSION = "2.0.0";
4040
internal static let CLIENT_IDENTIFIER = "Xendit iOS SDK";
41-
internal static let CLIENT_SDK_VERSION = "3.10.3";
41+
internal static let CLIENT_SDK_VERSION = "3.10.4";
4242

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

Xendit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Xendit'
3-
s.version = '3.10.3'
3+
s.version = '3.10.4'
44
s.license = 'MIT'
55
s.homepage = 'https://www.xendit.co'
66
s.author = { 'Juan Gonzalez’' => '[email protected]' }

0 commit comments

Comments
 (0)