Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal.shared.disconnectReader doesn't work when app is about to go in the background or terminate #330

Open
harsh7703 opened this issue Oct 27, 2024 · 6 comments

Comments

@harsh7703
Copy link

Summary

I want to disconnect the reader when the app is supposed to go in the background state or let's say it is about to terminate. This same code works when the app is foreground but does not work when the app is about to switch its state.

Code to reproduce


NotificationCenter.default.addObserver(self, selector: #selector(appWillEnterBackground), name: UIApplication.willResignActiveNotification, object: nil)

func appWillEnterBackground() {
      Terminal.shared.disconnectReader { error in
                if let error = error {
                    print("Disconnect failed: \(error)")
                } else {
                    print("--------------- Disconnected --------------")
                }
            }
}

iOS version

18.0.1

Installation method

Cocoapods

SDK version

3.9.1

Other information

@bric-stripe
Copy link
Collaborator

@harsh7703 some questions to help us:

  1. what reader type are you seeing this with?
  2. can you clarify the "does not work" state?
    • Are you seeing an error returned from disconnectReader? if so, what error?
    • or is it not calling your completion block? if so, does it call it when the app becomes active again?

@harsh7703
Copy link
Author

harsh7703 commented Oct 29, 2024

@bric-stripe - Hi
Ans 1: DeviceType: Stripe S700
Ans 2: I have already clarified in my question does not work state in as again under:-
~ I want to disconnect the reader when the app is supposed to go in the background state or let's say it is about to terminate state. This same code works when the app is foreground but does not work when the app is about to switch its background and terminated state. DisconnectFrom reader does not work not called completionblock. It is supposed to call before when applicationDidEnterBackground State.
Terminal.shared.disconnectReader { error in
if let error = error {
print("Disconnect failed: (error)")
} else {
print("--------------- Disconnected --------------")
}
}

@harsh7703
Copy link
Author

@bric-stripe - any update on this it would be fruitful for us to communicate with our clients using this device type?

@harsh7703
Copy link
Author

@bric-stripe -I have updated the SDK to version 4.0.0, but I am still encountering the same issue. Below is the error code that might help identify the root cause. This issue is blocking the release of the new app version, so I would appreciate your assistance in resolving it as soon as possible.

collectPaymentMethod failed: Error Domain=com.stripe-terminal Code=2020 "The command was canceled." UserInfo={NSLocalizedDescription=The command was canceled., com.stripe-terminal:Message=The command was canceled.}
errorCode::2020

@bric-stripe
Copy link
Collaborator

bric-stripe commented Nov 11, 2024

Hi, I'm investigating the disconnect issue as reported but can you clarify when you're seeing a collectPaymentMethod cancel error? Is it related to the original issue?

Canceled collectPaymentMethod is expected if cancel is requested on the cancelable or the user cancels on the reader. Could you provide a serial number for a reader where you're hitting this? And for the collectPaymentMethod issue can you provide a PaymentIntent ID so I can try to find some additional logging/timing to help me investigate / understand the problem.

@bric-stripe
Copy link
Collaborator

I've been unable to reproduce any issues disconnecting when going in to the background. Can you reproduce this with our repo's Example app? I added this simple diff to try to repro:

this is added at the end of AppDelegate.swift


+        NotificationCenter.default.addObserver(self, selector: #selector(appWillEnterBackground), name: UIApplication.willResignActiveNotification, object: nil)
+
         return true
     }

+    @objc
+    func appWillEnterBackground() {
+
+        disconnectLogger.error("---------------- Disconnecting -----")
+        Terminal.shared.disconnectReader { error in
+            if let error = error {
+                self.disconnectLogger.error("------------------ Disconnect failed: \(error)")
+            } else {
+                self.disconnectLogger.error("--------------- Disconnected Successfully --------------")
+            }
+        }
+    }

when an sPOS reader is connected I've only seen successful disconnects. Only error I've seen is when backgrounding and no reader is connected, but that's expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants